diff options
| author | Jérome Maes <jem@openerp.com> | 2017-06-19 13:22:30 +0200 |
|---|---|---|
| committer | Jérome Maes <jem@openerp.com> | 2017-06-20 09:00:47 +0200 |
| commit | 800d54e846b34f350bb4713c7c3cfc9e7a895c5b (patch) | |
| tree | 83b726c2407059e296fbcd7188da94128fa99dc3 /addons/phone_validation/tools | |
| parent | c124cb71c2d570a75a7e48d098a31b042d41bde4 (diff) | |
[FIX] phone_validation: bad code comparison
During the formating method, the country code
was compared to the country phone code. Indeed,
phonenumbers python lib return a `PhoneNumber`
object having a `country_code` attribute
refering to the country_phone_code, and not
the country_code (like odoo means).
Consequence: changing the country on a lead
did not make the phone validation work.
Thus, it was required to give both code (country
and country phone codes) to the phonenumbers API,
in order to make a correct verification.
Diffstat (limited to 'addons/phone_validation/tools')
| -rw-r--r-- | addons/phone_validation/tools/phone_validation.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/addons/phone_validation/tools/phone_validation.py b/addons/phone_validation/tools/phone_validation.py index 92b12cea1e0..e59af32f0e6 100644 --- a/addons/phone_validation/tools/phone_validation.py +++ b/addons/phone_validation/tools/phone_validation.py @@ -26,7 +26,15 @@ try: return phone_nbr - def phone_format(number, country_code, always_international=True, raise_exception=True): + def phone_format(number, country_code, country_phone_code, always_international=True, raise_exception=True): + """ Format the given phone number according to the localisation and international options. + :param number: number to convert + :param country_code: the ISO country code in two chars + :type country_code: str + :param country_phone_code: country dial in codes, defined by the ITU-T (Ex: 32 for Belgium) + :type country_phone_code: int + :rtype: str + """ try: phone_nbr = phone_parse(number, country_code) except (phonenumbers.phonenumberutil.NumberParseException, UserError) as e: @@ -35,8 +43,7 @@ try: else: _logger.warning(_('Unable to format %s:\n%s') % number, e) return number - - if always_international and phone_nbr.country_code != country_code: + if always_international and phone_nbr.country_code != country_phone_code: phone_fmt = phonenumbers.PhoneNumberFormat.INTERNATIONAL else: phone_fmt = phonenumbers.PhoneNumberFormat.NATIONAL @@ -48,7 +55,7 @@ except ImportError: def phone_parse(number, country_code): return False - def phone_format(number, country_code, always_international=True, raise_exception=True): + def phone_format(number, country_code, country_phone_code, always_international=True, raise_exception=True): global _phonenumbers_lib_warning if not _phonenumbers_lib_warning: _logger.warning( |
