diff --git a/base_phone/README.rst b/base_phone/README.rst index 1abb71f93..bac9a6db4 100644 --- a/base_phone/README.rst +++ b/base_phone/README.rst @@ -71,6 +71,7 @@ Contributors - Alexis de Lattre - Sébastien Beau +- Nikul Chaudhary Maintainers ----------- diff --git a/base_phone/__manifest__.py b/base_phone/__manifest__.py index 7f6c25bad..a5152c6f3 100644 --- a/base_phone/__manifest__.py +++ b/base_phone/__manifest__.py @@ -21,8 +21,11 @@ "views/res_users_view.xml", "wizard/reformat_all_phonenumbers_view.xml", "wizard/number_not_found_view.xml", - "views/web_phone.xml", ], - "qweb": ["static/src/xml/phone.xml"], + "assets": { + "web.assets_backend": [ + "base_phone/static/src/**/*", + ], + }, "installable": True, } diff --git a/base_phone/i18n/de.po b/base_phone/i18n/de.po index 63d7158b5..29a94bd98 100644 --- a/base_phone/i18n/de.po +++ b/base_phone/i18n/de.po @@ -40,13 +40,6 @@ msgstr "Abbruch" msgid "Click2dial successfull" msgstr "Click2dial erfolgreich" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Click2dial to %s" -msgstr "Click2dial gestartet" - #. module: base_phone #: model_terms:ir.ui.view,arch_db:base_phone.number_not_found_form #: model_terms:ir.ui.view,arch_db:base_phone.reformat_all_phonenumbers_form @@ -229,13 +222,6 @@ msgstr "Nummer nicht gefunden" msgid "Number converted to international format:" msgstr "Nummer in internationales Format umgewandelt:" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Number dialed: %s" -msgstr "Gewählte Nummer:" - #. module: base_phone #: model:ir.model,name:base_phone.model_number_not_found msgid "Number not found" diff --git a/base_phone/i18n/sl.po b/base_phone/i18n/sl.po index 83a9fb50e..9120b86f0 100644 --- a/base_phone/i18n/sl.po +++ b/base_phone/i18n/sl.po @@ -42,13 +42,6 @@ msgstr "Preklic" msgid "Click2dial successfull" msgstr "Click2dial uspešen" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Click2dial to %s" -msgstr "Click2dial zagnan" - #. module: base_phone #: model_terms:ir.ui.view,arch_db:base_phone.number_not_found_form #: model_terms:ir.ui.view,arch_db:base_phone.reformat_all_phonenumbers_form @@ -225,13 +218,6 @@ msgstr "Številka ni najdena" msgid "Number converted to international format:" msgstr "Številka pretvorjena v mednarodni format:" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Number dialed: %s" -msgstr "Klicana številka:" - #. module: base_phone #: model:ir.model,name:base_phone.model_number_not_found msgid "Number not found" diff --git a/base_phone/i18n/tr.po b/base_phone/i18n/tr.po index 4f64a67d1..e14c235e1 100644 --- a/base_phone/i18n/tr.po +++ b/base_phone/i18n/tr.po @@ -41,13 +41,6 @@ msgstr "İptal" msgid "Click2dial successfull" msgstr "Tıkla çevir başarılı" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Click2dial to %s" -msgstr "Tıkla çevir başlatıldı" - #. module: base_phone #: model_terms:ir.ui.view,arch_db:base_phone.number_not_found_form #: model_terms:ir.ui.view,arch_db:base_phone.reformat_all_phonenumbers_form @@ -224,13 +217,6 @@ msgstr "Numara Bulunamadı" msgid "Number converted to international format:" msgstr "Uluslarası biçime çevrilen numara:" -#. module: base_phone -#. openerp-web -#: code:addons/base_phone/static/src/js/phone_widget.js:0 -#, fuzzy, python-format -msgid "Number dialed: %s" -msgstr "Aranan numara:" - #. module: base_phone #: model:ir.model,name:base_phone.model_number_not_found msgid "Number not found" 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..040ab0d16 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)", @@ -143,7 +142,9 @@ def _get_phone_models(self): def click2dial(self, erp_number): """This function is designed to be overridden in IPBX-specific modules, such as asterisk_click2dial or ovh_telephony_connector""" - return {"dialed_number": erp_number} + return { + "dialed_number": erp_number, + } @api.model def convert_to_dial_number(self, erp_number): 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..df0bd691d 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.esm.js b/base_phone/static/src/js/phone_widget.esm.js new file mode 100644 index 000000000..87500ed8d --- /dev/null +++ b/base_phone/static/src/js/phone_widget.esm.js @@ -0,0 +1,92 @@ +/** @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). */ + +import {_t} from "@web/core/l10n/translation"; +import { + PhoneField, + formPhoneField, + phoneField, +} from "@web/views/fields/phone/phone_field"; +import {patch} from "@web/core/utils/patch"; +import {Component} from "@odoo/owl"; +import {useService} from "@web/core/utils/hooks"; + +export class Dial extends Component { + setup() { + this.orm = useService("orm"); + this.action = useService("action"); + } + get phoneHref() { + return "tel:" + this.props.record.data[this.props.name].replace(/\s+/g, ""); + } + async onClick() { + await this.props.record.save(); + var phone_num = this.props.record.data[this.props.name]; + this.env.services.notification.add(_t('Click2dial to "%s"', phone_num), { + type: "info", + }); + var params = { + phone_number: phone_num, + click2dial_model: this.props.record.resModel, + click2dial_id: this.props.record.resId, + }; + const result = await this.orm.call( + "phone.common", + "click2dial", + [phone_num], + {} + ); + if (result === false) { + this.env.services.notification.add(_t("Click2dial failed"), { + type: "warning", + }); + } else if (typeof result === "object") { + this.env.services.notification.add( + (_t("Number dialed: %s"), result.dialed_number), + {title: _t("Click2dial successfull"), type: "success"} + ); + if (result.action_model) { + this.action.doAction({ + type: "ir.actions.act_window", + name: result.action_name, + res_model: result.action_model, + views: [[false, "form"]], + target: "new", + context: params, + }); + } + } + } +} +Dial.template = "base_phone.Dial"; +Dial.props = ["*"]; + +patch(PhoneField, { + components: { + ...PhoneField.components, + Dial, + }, + defaultProps: { + ...PhoneField.defaultProps, + enableButton: true, + }, + props: { + ...PhoneField.props, + enableButton: {type: Boolean, optional: true}, + }, +}); + +const patchDescr = () => ({ + extractProps({options}) { + const props = super.extractProps(...arguments); + props.enableButton = options.enable_sms; + return props; + }, +}); + +patch(phoneField, patchDescr()); +patch(formPhoneField, patchDescr()); diff --git a/base_phone/static/src/js/phone_widget.js b/base_phone/static/src/js/phone_widget.js deleted file mode 100644 index e110ab702..000000000 --- a/base_phone/static/src/js/phone_widget.js +++ /dev/null @@ -1,110 +0,0 @@ -/* 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 */ - ); - }, - }); - - return { - FieldPhone: FieldPhone, - }; -}); diff --git a/base_phone/static/src/xml/phone.xml b/base_phone/static/src/xml/phone.xml index 2ee230382..94319ded8 100644 --- a/base_phone/static/src/xml/phone.xml +++ b/base_phone/static/src/xml/phone.xml @@ -4,16 +4,31 @@ @author: Alexis de Lattre License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - - - - - + + + + Dial + + + + + + + + + + + + + + + + + diff --git a/base_phone/tests/test_base_phone.py b/base_phone/tests/test_base_phone.py index 849e6729d..bba353d9b 100644 --- a/base_phone/tests/test_base_phone.py +++ b/base_phone/tests/test_base_phone.py @@ -32,9 +32,7 @@ def test_lookup(self): self.assertIsInstance(res, tuple) self.assertEqual(res[0], "res.partner") self.assertEqual(res[1], self.akretion.id) - self.assertEqual( - res[2], self.akretion.with_context(callerid=True).name_get()[0][1] - ) + self.assertEqual(res[2], self.akretion.with_context(callerid=True).display_name) res = self.phco.get_record_from_phone_number("0499889988") self.assertFalse(res) diff --git a/base_phone/views/web_phone.xml b/base_phone/views/web_phone.xml deleted file mode 100644 index 74670d119..000000000 --- a/base_phone/views/web_phone.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - -