From 16693873b34fce83837be4530b7bf171af6bcc65 Mon Sep 17 00:00:00 2001 From: Nikul-OSI Date: Mon, 12 Feb 2024 18:52:17 +0530 Subject: [PATCH] [MIG] base_phone: Migrated to v17 --- base_phone/README.rst | 1 + base_phone/__manifest__.py | 6 +- base_phone/models/__init__.py | 2 +- base_phone/models/models.py | 21 ++ base_phone/models/phone_common.py | 5 +- base_phone/models/phone_validation_mixin.py | 17 -- base_phone/models/res_partner.py | 15 +- base_phone/pyproject.toml | 3 + base_phone/readme/CONTRIBUTORS.md | 3 + base_phone/readme/DESCRIPTION.md | 14 ++ base_phone/static/description/index.html | 1 + base_phone/static/src/js/phone_widget.js | 220 +++++++++--------- base_phone/static/src/xml/phone.xml | 4 +- base_phone/tests/test_base_phone.py | 4 +- base_phone/views/web_phone.xml | 20 -- base_phone/wizard/number_not_found_view.xml | 7 +- .../wizard/reformat_all_phonenumbers.py | 2 +- .../wizard/reformat_all_phonenumbers_view.xml | 32 +-- base_phone/wizard/res_config_settings.xml | 48 ++-- requirements.txt | 2 + 20 files changed, 217 insertions(+), 210 deletions(-) create mode 100644 base_phone/models/models.py delete mode 100644 base_phone/models/phone_validation_mixin.py create mode 100644 base_phone/pyproject.toml create mode 100644 base_phone/readme/CONTRIBUTORS.md create mode 100644 base_phone/readme/DESCRIPTION.md delete mode 100644 base_phone/views/web_phone.xml create mode 100644 requirements.txt diff --git a/base_phone/README.rst b/base_phone/README.rst index 1abb71f93..56d60bfb3 100644 --- a/base_phone/README.rst +++ b/base_phone/README.rst @@ -71,6 +71,7 @@ Contributors - Alexis de Lattre - Sébastien Beau +- Nikul Chaudhary nchaudhary@opensourceintegrators.com Maintainers ----------- diff --git a/base_phone/__manifest__.py b/base_phone/__manifest__.py index 7f6c25bad..790851c5b 100644 --- a/base_phone/__manifest__.py +++ b/base_phone/__manifest__.py @@ -21,8 +21,12 @@ "views/res_users_view.xml", "wizard/reformat_all_phonenumbers_view.xml", "wizard/number_not_found_view.xml", - "views/web_phone.xml", ], + "assets": { + "web.assets_backend": [ + "base_phone/static/src/**/*", + ], + }, "qweb": ["static/src/xml/phone.xml"], "installable": True, } diff --git a/base_phone/models/__init__.py b/base_phone/models/__init__.py index 7d7547ee7..334ac7aaa 100644 --- a/base_phone/models/__init__.py +++ b/base_phone/models/__init__.py @@ -1,4 +1,4 @@ -from . import phone_validation_mixin +from . import models from . import res_company from . import res_partner from . import phone_common diff --git a/base_phone/models/models.py b/base_phone/models/models.py new file mode 100644 index 000000000..97c09a09b --- /dev/null +++ b/base_phone/models/models.py @@ -0,0 +1,21 @@ +# Copyright 2018-2021 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import models + + +class BaseModel(models.AbstractModel): + _inherit = "base" + + def _phone_format_number( + self, number, country, force_format="E164", raise_exception=False + ): + if "country_id" in self and self.country_id: + country = self.country_id + if "partner_id" in self and self.partner_id and self.partner_id.country_id: + country = self.partner_id.country_id + return super()._phone_format_number( + number, country, force_format, raise_exception + ) diff --git a/base_phone/models/phone_common.py b/base_phone/models/phone_common.py index 5d8d88f1d..51cc38d4f 100644 --- a/base_phone/models/phone_common.py +++ b/base_phone/models/phone_common.py @@ -25,8 +25,7 @@ def get_name_from_phone_number(self, presented_number): res = self.get_record_from_phone_number(presented_number) if res: return res[2] - else: - return False + return False @api.model def get_record_from_phone_number(self, presented_number): @@ -93,7 +92,7 @@ def get_record_from_phone_number(self, presented_number): res_obj = obj.browse(obj_id) # Use name_get()[0][1] instead of display_name # to take the context into account with the callerid key - name = res_obj.name_get()[0][1] + name = res_obj.display_name res = (obj._name, res_obj.id, name) _logger.debug( "Answer get_record_from_phone_number: (%s, %d, %s)", diff --git a/base_phone/models/phone_validation_mixin.py b/base_phone/models/phone_validation_mixin.py deleted file mode 100644 index 28fee6d5a..000000000 --- a/base_phone/models/phone_validation_mixin.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2018-2021 Akretion France (http://www.akretion.com/) -# @author: Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -from odoo import models - - -class PhoneValidationMixin(models.AbstractModel): - _inherit = "phone.validation.mixin" - - def _phone_get_country(self): - if "country_id" in self and self.country_id: - return self.country_id - if "partner_id" in self and self.partner_id and self.partner_id.country_id: - return self.partner_id.country_id - return self.env.company.country_id diff --git a/base_phone/models/res_partner.py b/base_phone/models/res_partner.py index 4b4c7908f..77b0c40e7 100644 --- a/base_phone/models/res_partner.py +++ b/base_phone/models/res_partner.py @@ -7,23 +7,16 @@ class ResPartner(models.Model): - _name = "res.partner" - # inherit on phone.validation.mixin (same as in crm_phone_validation, - # but base_phone only depends on phone_validation, - # not on crm_phone_validation) - _inherit = ["res.partner", "phone.validation.mixin"] + _inherit = "res.partner" _phone_name_sequence = 10 _phone_name_fields = ["phone", "mobile"] - def name_get(self): + def _compute_display_name(self): + super()._compute_display_name() if self._context.get("callerid"): - res = [] for partner in self: if partner.parent_id and partner.parent_id.is_company: name = f"{partner.parent_id.name}, {partner.name}" else: name = partner.name - res.append((partner.id, name)) - return res - else: - return super().name_get() + partner.display_name = name.strip() diff --git a/base_phone/pyproject.toml b/base_phone/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/base_phone/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_phone/readme/CONTRIBUTORS.md b/base_phone/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..787541ddd --- /dev/null +++ b/base_phone/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Alexis de Lattre \<\> +- Sébastien Beau \<\> +- Nikul Chaudhary \<\> diff --git a/base_phone/readme/DESCRIPTION.md b/base_phone/readme/DESCRIPTION.md new file mode 100644 index 000000000..bdc724915 --- /dev/null +++ b/base_phone/readme/DESCRIPTION.md @@ -0,0 +1,14 @@ +This module provides common methods and wizards which can be useful to +develop a connector between Odoo and a telephony system. It depends on +the official module *phone_validation* which handle the reformatting of +phone numbers using the +[phonenumbers](https://github.com/daviddrysdale/python-phonenumbers) +Python library, which is a port of the library used in Android +smartphones. For example, if your user is linked to a French company and +you update the form view of a partner with a badly written French phone +number such as '01-55-42-12-42', Odoo will automatically update the +phone number to [E.164](https://en.wikipedia.org/wiki/E.164) format +'+33155421242'. This module extends this reformatting to create() and +write() methods. + +This module is used by the Odoo-Asterisk connector of the OCA. diff --git a/base_phone/static/description/index.html b/base_phone/static/description/index.html index 3b759aae4..374088f84 100644 --- a/base_phone/static/description/index.html +++ b/base_phone/static/description/index.html @@ -416,6 +416,7 @@

Contributors

diff --git a/base_phone/static/src/js/phone_widget.js b/base_phone/static/src/js/phone_widget.js index e110ab702..2813a0547 100644 --- a/base_phone/static/src/js/phone_widget.js +++ b/base_phone/static/src/js/phone_widget.js @@ -1,110 +1,122 @@ +/** @odoo-module **/ + /* Base phone module for Odoo Copyright (C) 2013-2018 Akretion France @author: Alexis de Lattre License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -odoo.define("base_phone.updatedphone_widget", function (require) { - "use strict"; - - var core = require("web.core"); - var FieldPhone = require("web.basic_fields").FieldPhone; - var _t = core._t; - - FieldPhone.include({ - /* Always enable phone link tel:, not only on small screens */ - _canCall: function () { - return true; - }, - showDialButton: function () { - // Must be inherited by ipbx specific modules - // and set to true - return false; - }, - - _renderReadonly: function () { - // Create a link to trigger action on server - // this link will be after the - this._super(); - - if (!this.showDialButton()) { - return; - } - var self = this; - - // Create our link - var dial = $( - '
☎ Dial
' - ); - - // Add a parent element - // it's not possible to append to $el directly - // because $el don't have any parent yet - var parent = $("
"); - parent.append([this.$el[0], " ", dial]); - - // Replace this.$el by our new container - this.$el = parent; - - var phone_num = this.value; - /* eslint-disable no-unused-vars */ - dial.click(function (evt) { - self.click2dial(phone_num); - }); - /* eslint-enable no-unused-vars */ - }, - click2dial: function (phone_num) { - var self = this; - this.do_notify( - _.str.sprintf(_t("Click2dial to %s"), phone_num), - _t("Unhook your ringing phone"), - false - ); - var params = { - phone_number: phone_num, - click2dial_model: this.model, - click2dial_id: this.res_id, - }; - return this._rpc({ - model: "phone.common", - context: params, - method: "click2dial", - args: [phone_num], - }).then( - /* eslint-disable no-unused-vars */ - function (r) { - console.log("successfull", r); - if (r === false) { - self.do_warn("Click2dial failed"); - } else if (typeof r === "object") { - self.do_notify( - _t("Click2dial successfull"), - _.str.sprintf(_t("Number dialed: %s"), r.dialed_number), - false - ); - if (r.action_model) { - var action = { - name: r.action_name, - type: "ir.actions.act_window", - res_model: r.action_model, - view_mode: "form", - views: [[false, "form"]], - target: "new", - context: params, - }; - return self.do_action(action); - } - } - }, - function (r) { - console.log("on error"); - self.do_warn("Click2dial failed"); - } - /* eslint-enable no-unused-vars */ - ); - }, - }); +import {registry} from "@web/core/registry"; +import {_t} from "@web/core/l10n/translation"; +import { + PhoneField, + phoneField, + formPhoneField, +} from "@web/views/fields/phone/phone_field"; +import {patch} from "@web/core/utils/patch"; +import {Component, useRef, useState, onMounted} from "@odoo/owl"; - return { - FieldPhone: FieldPhone, - }; -}); +//odoo.define("base_phone.updatedphone_widget", function (require) { +// "use strict"; +// +// var core = require("web.core"); +// var FieldPhone = require("web.basic_fields").FieldPhone; +// var _t = core._t; +// +// FieldPhone.include({ +// /* Always enable phone link tel:, not only on small screens */ +// _canCall: function () { +// return true; +// }, +// showDialButton: function () { +// // Must be inherited by ipbx specific modules +// // and set to true +// return false; +// }, +// +// _renderReadonly: function () { +// // Create a link to trigger action on server +// // this link will be after the +// this._super(); +// +// if (!this.showDialButton()) { +// return; +// } +// var self = this; +// +// // Create our link +// var dial = $( +// '
☎ Dial
' +// ); +// +// // Add a parent element +// // it's not possible to append to $el directly +// // because $el don't have any parent yet +// var parent = $("
"); +// parent.append([this.$el[0], " ", dial]); +// +// // Replace this.$el by our new container +// this.$el = parent; +// +// var phone_num = this.value; +// /* eslint-disable no-unused-vars */ +// dial.click(function (evt) { +// self.click2dial(phone_num); +// }); +// /* eslint-enable no-unused-vars */ +// }, +// click2dial: function (phone_num) { +// var self = this; +// this.do_notify( +// _.str.sprintf(_t("Click2dial to %s"), phone_num), +// _t("Unhook your ringing phone"), +// false +// ); +// var params = { +// phone_number: phone_num, +// click2dial_model: this.model, +// click2dial_id: this.res_id, +// }; +// return this._rpc({ +// model: "phone.common", +// context: params, +// method: "click2dial", +// args: [phone_num], +// }).then( +// /* eslint-disable no-unused-vars */ +// function (r) { +// console.log("successfull", r); +// if (r === false) { +// self.do_warn("Click2dial failed"); +// } else if (typeof r === "object") { +// self.do_notify( +// _t("Click2dial successfull"), +// _.str.sprintf(_t("Number dialed: %s"), r.dialed_number), +// false +// ); +// if (r.action_model) { +// var action = { +// name: r.action_name, +// type: "ir.actions.act_window", +// res_model: r.action_model, +// view_mode: "form", +// views: [[false, "form"]], +// target: "new", +// context: params, +// }; +// return self.do_action(action); +// } +// } +// }, +// function (r) { +// console.log("on error"); +// self.do_warn("Click2dial failed"); +// } +// /* eslint-enable no-unused-vars */ +// ); +// }, +// }); +// +// return { +// FieldPhone: FieldPhone, +// }; +//}); diff --git a/base_phone/static/src/xml/phone.xml b/base_phone/static/src/xml/phone.xml index 2ee230382..4e7213176 100644 --- a/base_phone/static/src/xml/phone.xml +++ b/base_phone/static/src/xml/phone.xml @@ -4,8 +4,8 @@ @author: Alexis de Lattre License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - - + + - - -