Skip to content

Commit

Permalink
[MIG] base_phone: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Nov 28, 2024
1 parent efa249d commit ce5b9d6
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 60 deletions.
22 changes: 12 additions & 10 deletions base_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Base Phone
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github
:target: https://github.com/OCA/connector-telephony/tree/17.0/base_phone
:target: https://github.com/OCA/connector-telephony/tree/18.0/base_phone
:alt: OCA/connector-telephony
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/connector-telephony-17-0/connector-telephony-17-0-base_phone
:target: https://translation.odoo-community.org/projects/connector-telephony-18-0/connector-telephony-18-0-base_phone
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -54,7 +54,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-telephony/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/connector-telephony/issues/new?body=module:%20base_phone%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/connector-telephony/issues/new?body=module:%20base_phone%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -69,12 +69,14 @@ Authors
Contributors
------------

- Alexis de Lattre <alexis.delattre@akretion.com>
- Sébastien Beau <sebastien.beau@akretion.com>
- `Dixmit <https://www.dixmit.com>`__:
- Alexis de Lattre <alexis.delattre@akretion.com>
- Sébastien Beau <sebastien.beau@akretion.com>
- `Dixmit <https://www.dixmit.com>`__:

- Luis David Rodríguez
- Enric Tobella
- Luis David Rodríguez
- Enric Tobella

- ``Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>``\ \_

Maintainers
-----------
Expand All @@ -97,6 +99,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/connector-telephony <https://github.com/OCA/connector-telephony/tree/17.0/base_phone>`_ project on GitHub.
This module is part of the `OCA/connector-telephony <https://github.com/OCA/connector-telephony/tree/18.0/base_phone>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_phone/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Base Phone",
"version": "17.0.1.0.1",
"version": "18.0.1.0.1",
"category": "Phone",
"license": "AGPL-3",
"summary": "Validate phone numbers",
Expand Down
48 changes: 20 additions & 28 deletions base_phone/models/phone_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_record_from_phone_number(self, presented_number):
For example : ('res.partner', 42, 'Alexis de Lattre (Akretion)')
"""
_logger.debug(
"Call get_name_from_phone_number with number = %s" % presented_number
f"Call get_name_from_phone_number with number = {presented_number}"
)
if not isinstance(presented_number, str):
_logger.warning(
Expand All @@ -43,9 +43,7 @@ def get_record_from_phone_number(self, presented_number):
)
return False
if not presented_number.isdigit():
_logger.warning(
"Number '%s' should only contain digits." % presented_number
)
_logger.warning(f"Number '{presented_number}' should only contain digits.")

nr_digits_to_match_from_end = (
self.env.company.number_of_digits_to_match_from_end
Expand All @@ -62,50 +60,44 @@ def get_record_from_phone_number(self, presented_number):
obj = obj_dict["object"]
pg_search_number = "%" + end_number_to_match
_logger.debug(
"Will search phone and mobile numbers in %s ending with '%s'",
obj._name,
end_number_to_match,
f"Will search phone and mobile "
f"numbers in {obj._name} ending "
f"with '{end_number_to_match}'"
)
sql = "SELECT id FROM %s WHERE " % obj._table
sql = f"SELECT id FROM {obj._table} WHERE "
sql_where = []
sql_args = []
for field in obj_dict["fields"]:
sql_where.append("replace(%s, ' ', '') ilike %%s" % field)
sql_where.append(f"replace({field}, ' ', '') ilike %s")
sql_args.append(pg_search_number)
sql += " or ".join(sql_where)
_logger.debug(
"get_record_from_phone_number sql=%s sql_args=%s", sql, sql_args
)
_logger.debug(f"get_record_from_phone_number sql={sql} sql_args={sql_args}")
self._cr.execute(sql, tuple(sql_args))
res_sql = self._cr.fetchall()
if len(res_sql) > 1:
res_ids = [x[0] for x in res_sql]
_logger.warning(
"There are several %s (IDS = %s) with a phone number "
"ending with '%s'. Taking the first one.",
obj._name,
res_ids,
end_number_to_match,
f"There are several {obj._name} (IDS = {res_ids}) "
f"with a phone number "
f"ending with '{end_number_to_match}'. "
f"Taking the first one."
)
if res_sql:
obj_id = res_sql[0][0]
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)",
res[0],
res[1],
res[2],
f"Answer "
f"get_record_from_phone_number: ({res[0]}, {res[1]}, {res[2]})"
)
return res
else:
_logger.debug(
"No match on %s for end of phone number '%s'",
obj._name,
end_number_to_match,
f"No match on {obj._name} for end "
f"of phone number '{end_number_to_match}'"
)
return False

Expand Down Expand Up @@ -154,18 +146,18 @@ def convert_to_dial_number(self, erp_number):
the numbers.
"""
assert erp_number, "Missing phone number"
_logger.debug("Number before reformat = %s" % erp_number)
_logger.debug(f"Number before reformat = {erp_number}")
# erp_number are supposed to be in International format, so no need to
# give a country code here
parsed_num = phonenumbers.parse(erp_number, None)
country_code = self.env.company.country_id.code
assert country_code, "Missing country on company"
_logger.debug("Country code = %s" % country_code)
_logger.debug(f"Country code = {country_code}")
to_dial_number = phonenumbers.format_out_of_country_calling_number(
parsed_num, country_code.upper()
)
to_dial_number = to_dial_number.translate(
to_dial_number.maketrans("", "", " -.()/")
)
_logger.debug("Number to be sent to phone system: %s" % to_dial_number)
_logger.debug(f"Number to be sent to phone system: {to_dial_number}")
return to_dial_number
14 changes: 7 additions & 7 deletions base_phone/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import models
from odoo import api, models


class ResPartner(models.Model):
Expand All @@ -15,15 +15,15 @@ class ResPartner(models.Model):
_phone_name_sequence = 10
_phone_name_fields = ["phone", "mobile"]

def name_get(self):
@api.depends("name")
@api.depends_context("callerid")
def _compute_display_name(self):
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
name = partner.name or ""
partner.display_name = name
else:
return super().name_get()
return super()._compute_display_name()
1 change: 1 addition & 0 deletions base_phone/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- [Dixmit](https://www.dixmit.com):
- Luis David Rodríguez
- Enric Tobella
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`_
18 changes: 11 additions & 7 deletions base_phone/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Base Phone</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e25058f916eecfc291e866f796e6d8e5cfb8a085f04ebd160c905b6edfc2b168
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-telephony/tree/17.0/base_phone"><img alt="OCA/connector-telephony" src="https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-telephony-17-0/connector-telephony-17-0-base_phone"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-telephony/tree/18.0/base_phone"><img alt="OCA/connector-telephony" src="https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-telephony-18-0/connector-telephony-18-0-base_phone"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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 <em>phone_validation</em> which handle the reformatting of
Expand Down Expand Up @@ -399,7 +400,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/connector-telephony/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/connector-telephony/issues/new?body=module:%20base_phone%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/connector-telephony/issues/new?body=module:%20base_phone%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -420,18 +421,21 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Enric Tobella</li>
</ul>
</li>
<li><tt class="docutils literal">Heliconia Solutions Pvt. Ltd. <span class="pre">&lt;https://www.heliconia.io&gt;</span></tt>_</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector-telephony/tree/17.0/base_phone">OCA/connector-telephony</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector-telephony/tree/18.0/base_phone">OCA/connector-telephony</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
6 changes: 2 additions & 4 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 Expand Up @@ -103,5 +101,5 @@ def test_partner_phone_formatting(self):
pco = self.env["phone.common"]
name = pco.get_name_from_phone_number("0642774266")
self.assertEqual(name, "Pierre Paillet")
name2 = pco.get_name_from_phone_number("0041216191010")
name2 = pco.get_name_from_phone_number("0041216191010`")
self.assertEqual(name2, "C2C, Joël Grand-Guillaume")
2 changes: 1 addition & 1 deletion base_phone/wizard/number_not_found.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create_partner(self):
phonenumbers.number_type(parsed_num)

context = dict(self._context or {})
context["default_%s" % self.number_type] = self.e164_number
context[f"default_{self.number_type}"] = self.e164_number
action = {
"name": _("Create New Partner"),
"view_mode": "form,tree,kanban",
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 @@ -11,7 +11,7 @@

class ReformatAllPhonenumbers(models.TransientModel):
_name = "reformat.all.phonenumbers"
_inherit = "res.config.installer"
_inherit = "res.config.settings"
_description = "Reformat all phone numbers"

phonenumbers_not_reformatted = fields.Text(
Expand Down
2 changes: 1 addition & 1 deletion base_phone/wizard/reformat_all_phonenumbers_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
invisible="state not in ('draft')"
/>
<button
name="action_next"
name="execute"
type="object"
string="Close"
class="btn-primary"
Expand Down

0 comments on commit ce5b9d6

Please sign in to comment.