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/models | |
| 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/models')
| -rw-r--r-- | addons/phone_validation/models/phone_validation_mixin.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/addons/phone_validation/models/phone_validation_mixin.py b/addons/phone_validation/models/phone_validation_mixin.py index 8391e89cea3..6f8b3e18902 100644 --- a/addons/phone_validation/models/phone_validation_mixin.py +++ b/addons/phone_validation/models/phone_validation_mixin.py @@ -8,10 +8,10 @@ from odoo.addons.phone_validation.tools import phone_validation class PhoneValidationMixin(models.AbstractModel): _name = 'phone.validation.mixin' - def _phone_get_country_code(self): + def _phone_get_country(self): if 'country_id' in self: - return self.country_id.code - return self.env.user.company_id.country_id.code + return self.country_id + return self.env.user.company_id.country_id def _phone_get_always_international(self): if 'company_id' in self: @@ -19,11 +19,12 @@ class PhoneValidationMixin(models.AbstractModel): return self.env.user.company_id.phone_international_format def phone_format(self, number, country=None, company=None): - country_code = country.code if country else self._phone_get_country_code() + country = country or self._phone_get_country() always_international = company.phone_international_format if company else self._phone_get_always_international() - return phone_validation.phone_format( - number, country_code if country_code else None, + number, + country.code if country else None, + country.phone_code if country else None, always_international=always_international, raise_exception=True ) |
