Skip to content

Commit

Permalink
[MIG] base_phone: Migrated to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikul-OSI committed Jul 8, 2024
1 parent 3aada1c commit 31597dd
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 113 deletions.
3 changes: 1 addition & 2 deletions base_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ Contributors

- Alexis de Lattre <[email protected]>
- Sébastien Beau <[email protected]>

- Nikul Chaudhary <[email protected]>
- `Dixmit <https://www.dixmit.com>`__:

- Luis David Rodríguez
- Enric Tobella


Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion base_phone/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"assets": {
"web.assets_backend": [
"base_phone/static/src/components/**/*",
"base_phone/static/src/**/*",
],
},
"installable": True,
Expand Down
14 changes: 0 additions & 14 deletions base_phone/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ msgstr "Abbruch"
msgid "Click2dial successfull"
msgstr "Click2dial erfolgreich"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Click2dial to %s"
msgstr ""

#. 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
Expand Down Expand Up @@ -215,13 +208,6 @@ msgstr "Nummer nicht gefunden"
msgid "Number converted to international format:"
msgstr "Nummer in internationales Format umgewandelt:"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Number dialed: %s"
msgstr ""

#. module: base_phone
#: model:ir.model,name:base_phone.model_number_not_found
msgid "Number not found"
Expand Down
14 changes: 0 additions & 14 deletions base_phone/i18n/sl_SI.po
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ msgstr "Preklic"
msgid "Click2dial successfull"
msgstr "Click2dial uspešen"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Click2dial to %s"
msgstr ""

#. 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
Expand Down Expand Up @@ -209,13 +202,6 @@ msgstr "Številka ni najdena"
msgid "Number converted to international format:"
msgstr "Številka pretvorjena v mednarodni format:"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Number dialed: %s"
msgstr ""

#. module: base_phone
#: model:ir.model,name:base_phone.model_number_not_found
msgid "Number not found"
Expand Down
14 changes: 0 additions & 14 deletions base_phone/i18n/tr.po
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ msgstr "İptal"
msgid "Click2dial successfull"
msgstr "Tıkla çevir başarılı"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Click2dial to %s"
msgstr ""

#. 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
Expand Down Expand Up @@ -209,13 +202,6 @@ msgstr "Numara Bulunamadı"
msgid "Number converted to international format:"
msgstr "Uluslarası biçime çevrilen numara:"

#. module: base_phone
#. odoo-javascript
#: code:addons/base_phone/static/src/components/on_dial_button/on_dial_button.esm.js:0
#, python-format
msgid "Number dialed: %s"
msgstr ""

#. module: base_phone
#: model:ir.model,name:base_phone.model_number_not_found
msgid "Number not found"
Expand Down
2 changes: 1 addition & 1 deletion base_phone/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import phone_validation_mixin
from . import models
from . import res_company
from . import res_partner
from . import phone_common
21 changes: 21 additions & 0 deletions base_phone/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018-2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# 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

Check warning on line 18 in base_phone/models/models.py

View check run for this annotation

Codecov / codecov/patch

base_phone/models/models.py#L18

Added line #L18 was not covered by tests
return super()._phone_format_number(
number, country, force_format, raise_exception
)
9 changes: 5 additions & 4 deletions base_phone/models/phone_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 28 in base_phone/models/phone_common.py

View check run for this annotation

Codecov / codecov/patch

base_phone/models/phone_common.py#L28

Added line #L28 was not covered by tests

@api.model
def get_record_from_phone_number(self, presented_number):
Expand Down Expand Up @@ -92,7 +91,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)",
Expand Down Expand Up @@ -142,7 +141,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 {

Check warning on line 144 in base_phone/models/phone_common.py

View check run for this annotation

Codecov / codecov/patch

base_phone/models/phone_common.py#L144

Added line #L144 was not covered by tests
"dialed_number": erp_number,
}

@api.model
def convert_to_dial_number(self, erp_number):
Expand Down
16 changes: 5 additions & 11 deletions base_phone/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@


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):
res = 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()
return res
1 change: 1 addition & 0 deletions base_phone/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Alexis de Lattre \<<[email protected]>\>
- Sébastien Beau \<<[email protected]>\>
- Nikul Chaudhary \<<[email protected]>\>
- [Dixmit](https://www.dixmit.com):
- Luis David Rodríguez
- Enric Tobella
1 change: 1 addition & 0 deletions base_phone/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
<li>Sébastien Beau &lt;<a class="reference external" href="mailto:sebastien.beau&#64;akretion.com">sebastien.beau&#64;akretion.com</a>&gt;</li>
<li>Nikul Chaudhary &lt;<a class="reference external" href="mailto:nchaudhary&#64;opensourceintegrators.com">nchaudhary&#64;opensourceintegrators.com</a>&gt;</li>
<li><a class="reference external" href="https://www.dixmit.com">Dixmit</a>:<ul>
<li>Luis David Rodríguez</li>
<li>Enric Tobella</li>
Expand Down
92 changes: 92 additions & 0 deletions base_phone/static/src/js/phone_widget.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/** @odoo-module **/

/* Base phone module for Odoo
Copyright (C) 2013-2018 Akretion France
@author: Alexis de Lattre <[email protected]>
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());
34 changes: 34 additions & 0 deletions base_phone/static/src/xml/phone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2013-2018 Akretion France
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<templates xml:space="preserve">

<t t-name="base_phone.Dial">
<a
t-att-title="title"
t-att-href="phoneHref"
t-on-click.prevent.stop="onClick"
class="ms-3 d-inline-flex align-items-center o_field_phone_sms"
><i>☎</i><small class="fw-bold ms-1">Dial</small></a>
</t>

<t t-inherit="web.PhoneField" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_phone_content')]//a" position="after">
<t t-if="props.enableButton and props.record.data[props.name].length > 0">
<Dial t-props="props" />
</t>
</xpath>
</t>

<t t-inherit="web.FormPhoneField" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_phone_content')]" position="inside">
<t t-if="props.enableButton and props.record.data[props.name].length > 0">
<Dial t-props="props" />
</t>
</xpath>
</t>

</templates>
4 changes: 1 addition & 3 deletions base_phone/tests/test_base_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 2 additions & 5 deletions base_phone/wizard/number_not_found_view.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2012-2018 Akretion France
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<!-- Copyright 2012-2018 Akretion France @author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="number_not_found_form" model="ir.ui.view">
<field name="name">number.not.found.form</field>
Expand Down
2 changes: 1 addition & 1 deletion base_phone/wizard/reformat_all_phonenumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_reformat_all_phonenumbers(self):
vals = {}
for field in fields:
if entry[field]:
new_phone = entry.phone_format(entry[field])
new_phone = entry._phone_format(number=entry[field])

Check warning on line 41 in base_phone/wizard/reformat_all_phonenumbers.py

View check run for this annotation

Codecov / codecov/patch

base_phone/wizard/reformat_all_phonenumbers.py#L41

Added line #L41 was not covered by tests
if new_phone != entry[field]:
vals[field] = new_phone
if vals:
Expand Down
Loading

0 comments on commit 31597dd

Please sign in to comment.