[FIX] phone_validation: use international formatting in onchange

International formatting ease reading the value, which is handy in onchange.
This partially reverts odoo/odoo@51d571fab4 .

closes odoo/odoo#129851

X-original-commit: dab802a939c97603f70c504e98ecc92b0ac552f9
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2023-07-27 07:00:08 +02:00
parent f2bd7ec027
commit 2fc8a324d1
3 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -633,12 +633,12 @@ class Lead(models.Model):
@api.onchange('phone', 'country_id', 'company_id')
def _onchange_phone_validation(self):
if self.phone:
self.phone = self.phone_get_sanitized_number(number_fname='phone', force_format='E164') or self.phone
self.phone = self.phone_get_sanitized_number(number_fname='phone', force_format='INTERNATIONAL') or self.phone
@api.onchange('mobile', 'country_id', 'company_id')
def _onchange_mobile_validation(self):
if self.mobile:
self.mobile = self.phone_get_sanitized_number(number_fname='mobile', force_format='E164') or self.mobile
self.mobile = self.phone_get_sanitized_number(number_fname='mobile', force_format='INTERNATIONAL') or self.mobile
def _prepare_values_from_partner(self, partner):
""" Get a dictionary with values coming from partner information to
+8 -8
View File
@@ -347,9 +347,9 @@ class TestCRMLead(TestCrmCommon):
# reset partner phone to a local number and prepare formatted / sanitized values
partner_phone, partner_mobile = self.test_phone_data[2], self.test_phone_data[1]
partner_phone_formatted = phone_format(partner_phone, 'US', '1')
partner_phone_formatted = phone_format(partner_phone, 'US', '1', force_format='INTERNATIONAL')
partner_phone_sanitized = phone_format(partner_phone, 'US', '1', force_format='E164')
partner_mobile_formatted = phone_format(partner_mobile, 'US', '1')
partner_mobile_formatted = phone_format(partner_mobile, 'US', '1', force_format='INTERNATIONAL')
partner_mobile_sanitized = phone_format(partner_mobile, 'US', '1', force_format='E164')
partner_email, partner_email_normalized = self.test_email_data[2], self.test_email_data_normalized[2]
self.assertEqual(partner_phone_formatted, '+1 202-555-0888')
@@ -365,9 +365,9 @@ class TestCRMLead(TestCrmCommon):
# as well as mobile (who does not trigger the reverse sync)
lead_form.partner_id = partner
self.assertEqual(lead_form.email_from, partner_email)
self.assertEqual(lead_form.phone, partner_phone_sanitized,
self.assertEqual(lead_form.phone, partner_phone_formatted,
'Lead: form automatically formats numbers')
self.assertEqual(lead_form.mobile, partner_mobile_sanitized,
self.assertEqual(lead_form.mobile, partner_mobile_formatted,
'Lead: form automatically formats numbers')
self.assertFalse(lead_form.partner_email_update)
self.assertFalse(lead_form.partner_phone_update)
@@ -379,9 +379,9 @@ class TestCRMLead(TestCrmCommon):
'Lead / Partner: partner values sent to lead')
self.assertEqual(lead.email_normalized, partner_email_normalized,
'Lead / Partner: equal emails should lead to equal normalized emails')
self.assertEqual(lead.phone, partner_phone_sanitized,
self.assertEqual(lead.phone, partner_phone_formatted,
'Lead / Partner: partner values (formatted) sent to lead')
self.assertEqual(lead.mobile, partner_mobile_sanitized,
self.assertEqual(lead.mobile, partner_mobile_formatted,
'Lead / Partner: partner values (formatted) sent to lead')
self.assertEqual(lead.phone_sanitized, partner_mobile_sanitized,
'Lead: phone_sanitized computed field on mobile')
@@ -406,7 +406,7 @@ class TestCRMLead(TestCrmCommon):
lead_form.email_from = new_email
self.assertTrue(lead_form.partner_email_update)
new_phone = '+1 202 555 7799'
new_phone_formatted = phone_format(new_phone, 'US', '1', force_format="E164")
new_phone_formatted = phone_format(new_phone, 'US', '1', force_format="INTERNATIONAL")
lead_form.phone = new_phone
self.assertEqual(lead_form.phone, new_phone_formatted)
self.assertTrue(lead_form.partner_email_update)
@@ -419,7 +419,7 @@ class TestCRMLead(TestCrmCommon):
# LEAD/PARTNER SYNC: mobile does not update partner
new_mobile = '+1 202 555 6543'
new_mobile_formatted = phone_format(new_mobile, 'US', '1', force_format="E164")
new_mobile_formatted = phone_format(new_mobile, 'US', '1', force_format="INTERNATIONAL")
lead_form.mobile = new_mobile
lead_form.save()
self.assertEqual(lead.mobile, new_mobile_formatted)
@@ -11,14 +11,14 @@ class Partner(models.Model):
@api.onchange('phone', 'country_id', 'company_id')
def _onchange_phone_validation(self):
if self.phone:
self.phone = self._phone_format(self.phone)
self.phone = self._phone_format(self.phone, force_format='INTERNATIONAL')
@api.onchange('mobile', 'country_id', 'company_id')
def _onchange_mobile_validation(self):
if self.mobile:
self.mobile = self._phone_format(self.mobile)
self.mobile = self._phone_format(self.mobile, force_format='INTERNATIONAL')
def _phone_format(self, number, country=None, company=None):
def _phone_format(self, number, country=None, company=None, force_format='E164'):
country = country or self.country_id or self.env.company.country_id
if not country or not number:
return number
@@ -26,7 +26,7 @@ class Partner(models.Model):
number,
country.code if country else None,
country.phone_code if country else None,
force_format='E164',
force_format=force_format,
raise_exception=False
)