summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2021-05-11 14:35:12 +0000
committerThibault Delavallée <tde@odoo.com>2021-05-11 14:35:14 +0000
commitf593cdab18c4700af5d4e04a0aa7c6b367488f70 (patch)
treee78a1d9a7dad07a7e355af79b56074fbe62c5790 /addons
parent4b0c551194e8ef66df9136629afe71566ffe212e (diff)
[FIX] phone_validation: add country trigger on sanitize phone computation
If country is updated on a record inheriting from mail.thread.phone its sanitized number should be computed again. Indeed without this trigger it is not computed and may lead to inconsistencies between phone numbers and sanitized number. Task ID-2528169 closes odoo/odoo#70684 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/tests/test_crm_lead.py6
-rw-r--r--addons/phone_validation/models/mail_thread_phone.py7
2 files changed, 12 insertions, 1 deletions
diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py
index 54df5adf79f..b1c2716674f 100644
--- a/addons/crm/tests/test_crm_lead.py
+++ b/addons/crm/tests/test_crm_lead.py
@@ -408,6 +408,12 @@ class TestCRMLead(TestCrmCommon):
self.assertEqual(lead.mobile, self.test_phone_data[2])
self.assertEqual(lead.phone_sanitized, self.test_phone_data_sanitized[2])
+ # updating country should trigger sanitize computation
+ lead.write({'country_id': self.env.ref('base.be').id})
+ self.assertEqual(lead.phone, self.test_phone_data[1])
+ self.assertEqual(lead.mobile, self.test_phone_data[2])
+ self.assertFalse(lead.phone_sanitized)
+
@users('user_sales_manager')
def test_phone_mobile_search(self):
lead_1 = self.env['crm.lead'].create({
diff --git a/addons/phone_validation/models/mail_thread_phone.py b/addons/phone_validation/models/mail_thread_phone.py
index 7eacb84d5c6..f81da543678 100644
--- a/addons/phone_validation/models/mail_thread_phone.py
+++ b/addons/phone_validation/models/mail_thread_phone.py
@@ -43,7 +43,7 @@ class PhoneMixin(models.AbstractModel):
help="Indicates if a blacklisted sanitized phone number is a mobile number. Helps distinguish which number is blacklisted \
when there is both a mobile and phone field in a model.")
- @api.depends(lambda self: self._phone_get_number_fields())
+ @api.depends(lambda self: self._phone_get_sanitize_triggers())
def _compute_phone_sanitized(self):
self._assert_phone_field()
number_fields = self._phone_get_number_fields()
@@ -113,6 +113,11 @@ class PhoneMixin(models.AbstractModel):
if not any(fname in self and self._fields[fname].type == 'char' for fname in self._phone_get_number_fields()):
raise UserError(_('Invalid primary phone field on model %s', self._name))
+ def _phone_get_sanitize_triggers(self):
+ """ Tool method to get all triggers for sanitize """
+ res = [self._phone_get_country_field()] if self._phone_get_country_field() else []
+ return res + self._phone_get_number_fields()
+
def _phone_get_number_fields(self):
""" This method returns the fields to use to find the number to use to
send an SMS on a record. """