summaryrefslogtreecommitdiff
path: root/addons/phone_validation/models
diff options
context:
space:
mode:
authorRémi Rahir <rar@odoo.com>2018-02-06 10:08:35 +0100
committerRémi Rahir <rar@odoo.com>2018-02-07 14:22:46 +0100
commit376415052c67ad2e63baa06410c964077e2deee4 (patch)
treebafc2bd4c1e72995101418fbb54fd76ba8987772 /addons/phone_validation/models
parent2c6bad6b75c9c9f66abc4bdbecace74536556adc (diff)
[FIX] phone_validation, crm_phone_validation: Phone number parsing
Before this commit, when filing a phone number field on a model form (typically on website_form), the module phonenumbers would try to parse the number against the country of the model. However, this call fails when the number starts with 00 instead of + and that the model doesn't have a country_id field or if said field is not set. For this specific case, we chose to skip the number parsing altogether as providing a default country to the parser can lead to a wrong parsing. i.e, phonenumbers.parse(+32477111111, 'US') will find the number as US-based when it is a belgian number. solves issue #22513 Also corrected a faulty behaviour where the option to have a number parsed in its international format field `phone_international_format` on `res.company` was never properly assessed when the field comany_id of a model was not present in the model's form view. Added company_id field on opportunity's form view for a proper fix. Also fixed a syntax error in a logger.
Diffstat (limited to 'addons/phone_validation/models')
-rw-r--r--addons/phone_validation/models/phone_validation_mixin.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/addons/phone_validation/models/phone_validation_mixin.py b/addons/phone_validation/models/phone_validation_mixin.py
index 1003ab929f2..4cd9d8eb2bb 100644
--- a/addons/phone_validation/models/phone_validation_mixin.py
+++ b/addons/phone_validation/models/phone_validation_mixin.py
@@ -11,20 +11,21 @@ class PhoneValidationMixin(models.AbstractModel):
def _phone_get_country(self):
if 'country_id' in self:
return self.country_id
- return self.env.user.company_id.country_id
def _phone_get_always_international(self):
- if 'company_id' in self:
+ if 'company_id' in self and self.country_id:
return self.company_id.phone_international_format == 'prefix'
return self.env.user.company_id.phone_international_format == 'prefix'
def phone_format(self, number, country=None, company=None):
country = country or self._phone_get_country()
+ if not country:
+ return number
always_international = company.phone_international_format == 'prefix' if company else self._phone_get_always_international()
return phone_validation.phone_format(
number,
country.code if country else None,
country.phone_code if country else None,
always_international=always_international,
- raise_exception=True
+ raise_exception=False
)