Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G2P-2175 sanitized phone number and deduplication #134

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions g2p_registry_base/models/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from odoo import _, api, exceptions, fields, models

from odoo.addons.phone_validation.tools import phone_validation

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -44,10 +42,11 @@ def _compute_phone_sanitized(self):
if rec.phone_no:
number = rec["phone_no"]
sanitized = str(
self.env.user._phone_format(
rec._phone_format(
number=number,
country=rec.country_id,
force_format="E164",
raise_exception=True,
)
)
rec.phone_sanitized = sanitized
Expand All @@ -57,24 +56,12 @@ def _onchange_phone_validation(self):
PHONE_REGEX = self.env["ir.config_parameter"].get_param("g2p_registry.phone_regex")
if not self.phone_no:
return
self.phone_no = self._phone_format(self.phone_no)
self.phone_no = self.env["g2p.phone.number"]._phone_format(number=self.phone_no)
_logger.debug(f"phone_no: {self.phone_no}")
if PHONE_REGEX:
if not re.match(PHONE_REGEX, self.phone_no):
raise models.ValidationError(_("Invalid phone number!"))

def _phone_format(self, number, country=None):
country = country or self.country_id or self.env.company.country_id
if not country:
return number
return phone_validation.phone_format(
number,
country.code if country else None,
country.phone_code if country else None,
force_format="INTERNATIONAL",
raise_exception=False,
)

def disable_phone(self):
for rec in self:
if not rec.disabled:
Expand Down
7 changes: 4 additions & 3 deletions g2p_registry_base/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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
15 changes: 0 additions & 15 deletions g2p_registry_base/tests/test_phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ def test_05_check_date_collected(self):
except Exception as e:
_logger.debug(f"Caught exception: {e}")

def test_06_phone_format(self):
phone_number = self.env["g2p.phone.number"].create(
{
"partner_id": self.partner.id,
"phone_no": "+919876543210",
"country_id": self.country_india.id,
}
)
formatted_number = phone_number._phone_format("+919876543210", self.country_india)
expected_number = "+919876543210"
formatted_number_digits_only = "".join(char for char in formatted_number if char.isdigit())
expected_number_digits_only = "".join(char for char in expected_number if char.isdigit())

self.assertEqual(expected_number_digits_only, formatted_number_digits_only)

def test_07_compute_phone_sanitized(self):
phone_number = self.env["g2p.phone.number"].create(
{
Expand Down
Loading