From 71f19d55fa6c484ffb7816caad24312ddba635bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 11 May 2021 14:35:12 +0000 Subject: [PATCH] [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#70734 X-original-commit: odoo/odoo@d00b2911673a79e8a49cf495b4fb083d9bb1f532 Signed-off-by: Thibault Delavallee (tde) --- addons/crm/tests/test_crm_lead.py | 6 ++++++ addons/crm_sms/tests/test_crm_lead.py | 2 +- addons/phone_validation/models/mail_thread_phone.py | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py index 109ddefdd20..082d7642af6 100644 --- a/addons/crm/tests/test_crm_lead.py +++ b/addons/crm/tests/test_crm_lead.py @@ -537,3 +537,9 @@ class TestCRMLead(TestCrmCommon): self.assertEqual(lead.phone, self.test_phone_data[1]) 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) diff --git a/addons/crm_sms/tests/test_crm_lead.py b/addons/crm_sms/tests/test_crm_lead.py index f5659da8301..2ea9a073363 100644 --- a/addons/crm_sms/tests/test_crm_lead.py +++ b/addons/crm_sms/tests/test_crm_lead.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.crm.tests.common import TestCrmCommon -from odoo.tests.common import Form, users +from odoo.tests.common import users class TestCRMLead(TestCrmCommon): diff --git a/addons/phone_validation/models/mail_thread_phone.py b/addons/phone_validation/models/mail_thread_phone.py index 44ad7d8bdd1..5d844b0aa96 100644 --- a/addons/phone_validation/models/mail_thread_phone.py +++ b/addons/phone_validation/models/mail_thread_phone.py @@ -92,7 +92,7 @@ class PhoneMixin(models.AbstractModel): return [(0, '=', 1)] return [('id', 'in', [r[0] for r in res])] - @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() @@ -162,6 +162,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. """