[IMP] partner_phone_country_validation:
quick fix
This commit is contained in:
@@ -19,22 +19,39 @@ class Partner(models.Model):
|
||||
self.format_mobile_from_country()
|
||||
self.format_phone_from_country()
|
||||
|
||||
def format_number_zerozero(self, number):
|
||||
if number.startswith("00"):
|
||||
number = "+"+number[2:]
|
||||
return number
|
||||
|
||||
def format_phone_from_country(self):
|
||||
if self.phone:
|
||||
if not self.phone.startswith("00") and not self.phone.startswith('+'):
|
||||
self.phone = self.phone_format(self.phone)
|
||||
country = None
|
||||
if self.phone.startswith('+'):
|
||||
country = self.env['res.country'].search(
|
||||
[('code', '=', get_country_from_phone_number(self.phone))], limit=1
|
||||
)
|
||||
if self.country_id:
|
||||
country = self.country_id
|
||||
if country:
|
||||
self.phone = self.phone_format(self.phone, country=country)
|
||||
|
||||
def format_mobile_from_country(self):
|
||||
if self.mobile:
|
||||
if not self.mobile.startswith("00") and not self.mobile.startswith('+'):
|
||||
self.mobile = self.phone_format(self.mobile)
|
||||
country = None
|
||||
if self.mobile.startswith('+'):
|
||||
country = self.env['res.country'].search(
|
||||
[('code', '=', get_country_from_phone_number(self.mobile))], limit=1
|
||||
)
|
||||
if self.country_id:
|
||||
country = self.country_id
|
||||
if country:
|
||||
self.mobile = self.phone_format(self.mobile, country=country)
|
||||
|
||||
def set_country_from_phone_number(self, phone_number):
|
||||
country = self.env['res.country'].search(
|
||||
[('code', '=', get_country_from_phone_number(phone_number))], limit=1
|
||||
)
|
||||
if not country and not self.country_id:
|
||||
self.country_id = self.env.company.country_id
|
||||
if country and not self.country_id:
|
||||
self.country_id = country
|
||||
|
||||
@@ -42,6 +59,7 @@ class Partner(models.Model):
|
||||
def _onchange_phone_validation(self):
|
||||
# If no country is found, we define the country based on the beginning of the number
|
||||
if self.phone:
|
||||
self.phone = self.format_number_zerozero(self.phone)
|
||||
self.set_country_from_phone_number(self.phone)
|
||||
self.format_phone_from_country()
|
||||
|
||||
@@ -50,5 +68,6 @@ class Partner(models.Model):
|
||||
def _onchange_mobile_validation(self):
|
||||
# If no country is found, we define the country based on the beginning of the number
|
||||
if self.mobile:
|
||||
self.mobile = self.format_number_zerozero(self.mobile)
|
||||
self.set_country_from_phone_number(self.mobile)
|
||||
self.format_mobile_from_country()
|
Reference in New Issue
Block a user