changeset 98707df1f50a in modules/party:default
details: https://hg.tryton.org/modules/party?cmd=changeset&node=98707df1f50a
description:
        Always validate phone number when parsing

        issue10574
        review372451002
diffstat:

 contact_mechanism.py |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 97b575fc91e5 -r 98707df1f50a contact_mechanism.py
--- a/contact_mechanism.py      Tue Oct 12 10:07:14 2021 +0200
+++ b/contact_mechanism.py      Sat Oct 30 02:16:16 2021 +0200
@@ -141,9 +141,12 @@
         for country_code in chain(self._phone_country_codes(), [None]):
             try:
                 # Country code is ignored if value has an international prefix
-                return phonenumbers.parse(value, country_code)
+                phonenumber = phonenumbers.parse(value, country_code)
             except NumberParseException:
                 pass
+            else:
+                if phonenumbers.is_valid_number(phonenumber):
+                    return phonenumber
         return None
 
     @fields.depends(methods=['_parse_phonenumber'])
@@ -266,8 +269,7 @@
     def check_valid_phonenumber(self):
         if not phonenumbers or self.type not in _PHONE_TYPES:
             return
-        phonenumber = self._parse_phonenumber(self.value)
-        if not (phonenumber and phonenumbers.is_valid_number(phonenumber)):
+        if not self._parse_phonenumber(self.value):
             raise InvalidPhoneNumber(
                 gettext('party.msg_invalid_phone_number',
                     phone=self.value, party=self.party.rec_name))

Reply via email to