summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2021-05-11 14:14:00 +0000
committerThibault Delavallée <tde@odoo.com>2021-05-11 14:27:50 +0000
commit4b0c551194e8ef66df9136629afe71566ffe212e (patch)
tree42fdc555e5081df99dbb3d6e94901df47f9a37e0 /addons
parentd0db984990679a63714ca62e6b605d94af7d5c28 (diff)
[FIX] crm: correctly compute phone_sanitized without having crm_sms installed
Currently phone_sanitized computation on lead model works only if crm_sms is installed. Indeed an override of ``_phone_get_number_fields`` is missing. However ``_sms_get_number_fields`` coming with ``crm_sms`` and its ``sms`` dependency hides the issue as those modules are auto-install. However if ``crm_sms`` is uninstalled phone_sanitized is not correctly computed anymore. Task ID-2528169 Oversight of odoo/odoo#45315
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/models/crm_lead.py4
-rw-r--r--addons/crm/tests/common.py10
-rw-r--r--addons/crm/tests/test_crm_lead.py29
-rw-r--r--addons/crm_sms/models/crm_lead.py1
-rw-r--r--addons/crm_sms/tests/__init__.py3
-rw-r--r--addons/crm_sms/tests/test_crm_lead.py29
-rw-r--r--addons/mass_mailing_sms/models/mailing_contact.py1
-rw-r--r--addons/sms/models/res_partner.py1
-rw-r--r--addons/test_mail_full/models/test_mail_models.py1
9 files changed, 70 insertions, 9 deletions
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index 03127b46899..7c8e0c5e3aa 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -1516,6 +1516,10 @@ class Lead(models.Model):
break
return result
+ def _phone_get_number_fields(self):
+ """ Use mobile or phone fields to compute sanitized phone number """
+ return ['mobile', 'phone']
+
@api.model
def get_import_templates(self):
return [{
diff --git a/addons/crm/tests/common.py b/addons/crm/tests/common.py
index cc880bad7ca..18e56378394 100644
--- a/addons/crm/tests/common.py
+++ b/addons/crm/tests/common.py
@@ -129,12 +129,12 @@ class TestCrmCommon(TestSalesCommon, MailCase):
'philip.j.fry@test.example.com',
'turanga.leela@test.example.com',
]
- cls.test_pĥone_data = [
+ cls.test_phone_data = [
'+1 202 555 0122', # formatted US number
'202 555 0999', # local US number
'202 555 0888', # local US number
]
- cls.test_pĥone_data_sanitized = [
+ cls.test_phone_data_sanitized = [
'+12025550122',
'+12025550999',
'+12025550888',
@@ -153,7 +153,7 @@ class TestCrmCommon(TestSalesCommon, MailCase):
cls.contact_1 = cls.env['res.partner'].create({
'name': 'Philip J Fry',
'email': cls.test_email_data[1],
- 'mobile': cls.test_pĥone_data[0],
+ 'mobile': cls.test_phone_data[0],
'title': cls.env.ref('base.res_partner_title_mister').id,
'function': 'Delivery Boy',
'phone': False,
@@ -167,8 +167,8 @@ class TestCrmCommon(TestSalesCommon, MailCase):
cls.contact_2 = cls.env['res.partner'].create({
'name': 'Turanga Leela',
'email': cls.test_email_data[2],
- 'mobile': cls.test_pĥone_data[1],
- 'phone': cls.test_pĥone_data[2],
+ 'mobile': cls.test_phone_data[1],
+ 'phone': cls.test_phone_data[2],
'parent_id': False,
'is_company': False,
'street': 'Cookieville Minimum-Security Orphanarium',
diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py
index 119f356a251..54df5adf79f 100644
--- a/addons/crm/tests/test_crm_lead.py
+++ b/addons/crm/tests/test_crm_lead.py
@@ -217,16 +217,16 @@ class TestCRMLead(TestCrmCommon):
lead_form = Form(lead)
# reset partner phone to a local number and prepare formatted / sanitized values
- partner_phone, partner_mobile = self.test_pĥone_data[2], self.test_pĥone_data[1]
+ 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_sanitized = phone_format(partner_phone, 'US', '1', force_format='E164')
partner_mobile_formatted = phone_format(partner_mobile, 'US', '1')
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')
- self.assertEqual(partner_phone_sanitized, self.test_pĥone_data_sanitized[2])
+ self.assertEqual(partner_phone_sanitized, self.test_phone_data_sanitized[2])
self.assertEqual(partner_mobile_formatted, '+1 202-555-0999')
- self.assertEqual(partner_mobile_sanitized, self.test_pĥone_data_sanitized[1])
+ self.assertEqual(partner_mobile_sanitized, self.test_phone_data_sanitized[1])
# ensure initial data
self.assertEqual(partner.phone, partner_phone)
self.assertEqual(partner.mobile, partner_mobile)
@@ -388,13 +388,34 @@ class TestCRMLead(TestCrmCommon):
self.assertEqual(new_lead.partner_id.team_id, self.sales_team_1)
@users('user_sales_manager')
+ def test_phone_mobile_update(self):
+ lead = self.env['crm.lead'].create({
+ 'name': 'Lead 1',
+ 'country_id': self.env.ref('base.us').id,
+ 'phone': self.test_phone_data[0],
+ })
+ self.assertEqual(lead.phone, self.test_phone_data[0])
+ self.assertFalse(lead.mobile)
+ self.assertEqual(lead.phone_sanitized, self.test_phone_data_sanitized[0])
+
+ lead.write({'phone': False, 'mobile': self.test_phone_data[1]})
+ self.assertFalse(lead.phone)
+ self.assertEqual(lead.mobile, self.test_phone_data[1])
+ self.assertEqual(lead.phone_sanitized, self.test_phone_data_sanitized[1])
+
+ lead.write({'phone': self.test_phone_data[1], 'mobile': self.test_phone_data[2]})
+ 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])
+
+ @users('user_sales_manager')
def test_phone_mobile_search(self):
lead_1 = self.env['crm.lead'].create({
'name': 'Lead 1',
'country_id': self.env.ref('base.be').id,
'phone': '+32485001122',
})
- lead_2 = self.env['crm.lead'].create({
+ _lead_2 = self.env['crm.lead'].create({
'name': 'Lead 2',
'country_id': self.env.ref('base.be').id,
'phone': '+32485112233',
diff --git a/addons/crm_sms/models/crm_lead.py b/addons/crm_sms/models/crm_lead.py
index 19e4379339e..76f7301cdfd 100644
--- a/addons/crm_sms/models/crm_lead.py
+++ b/addons/crm_sms/models/crm_lead.py
@@ -10,4 +10,5 @@ class CrmLead(models.Model):
def _sms_get_number_fields(self):
""" This method returns the fields to use to find the number to use to
send an SMS on a record. """
+ # TDE FIXME: to be cleaned in 14.4+ as it conflicts with _phone_get_number_fields
return ['mobile', 'phone']
diff --git a/addons/crm_sms/tests/__init__.py b/addons/crm_sms/tests/__init__.py
new file mode 100644
index 00000000000..e6f86243ac6
--- /dev/null
+++ b/addons/crm_sms/tests/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import test_crm_lead
diff --git a/addons/crm_sms/tests/test_crm_lead.py b/addons/crm_sms/tests/test_crm_lead.py
new file mode 100644
index 00000000000..f5659da8301
--- /dev/null
+++ b/addons/crm_sms/tests/test_crm_lead.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+# 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
+
+
+class TestCRMLead(TestCrmCommon):
+
+ @users('user_sales_manager')
+ def test_phone_mobile_update(self):
+ lead = self.env['crm.lead'].create({
+ 'name': 'Lead 1',
+ 'country_id': self.env.ref('base.us').id,
+ 'phone': self.test_phone_data[0],
+ })
+ self.assertEqual(lead.phone, self.test_phone_data[0])
+ self.assertFalse(lead.mobile)
+ self.assertEqual(lead.phone_sanitized, self.test_phone_data_sanitized[0])
+
+ lead.write({'phone': False, 'mobile': self.test_phone_data[1]})
+ self.assertFalse(lead.phone)
+ self.assertEqual(lead.mobile, self.test_phone_data[1])
+ self.assertEqual(lead.phone_sanitized, self.test_phone_data_sanitized[1])
+
+ lead.write({'phone': self.test_phone_data[1], 'mobile': self.test_phone_data[2]})
+ 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])
diff --git a/addons/mass_mailing_sms/models/mailing_contact.py b/addons/mass_mailing_sms/models/mailing_contact.py
index 68050b519d3..73a3431e156 100644
--- a/addons/mass_mailing_sms/models/mailing_contact.py
+++ b/addons/mass_mailing_sms/models/mailing_contact.py
@@ -11,4 +11,5 @@ class MailingContact(models.Model):
mobile = fields.Char(string='Mobile')
def _sms_get_number_fields(self):
+ # TDE note: should override _phone_get_number_fields but ok as sms is in dependencies
return ['mobile']
diff --git a/addons/sms/models/res_partner.py b/addons/sms/models/res_partner.py
index 987791da643..3159cb98575 100644
--- a/addons/sms/models/res_partner.py
+++ b/addons/sms/models/res_partner.py
@@ -17,4 +17,5 @@ class ResPartner(models.Model):
def _sms_get_number_fields(self):
""" This method returns the fields to use to find the number to use to
send an SMS on a record. """
+ # TDE note: should override _phone_get_number_fields but ok as sms override it
return ['mobile', 'phone']
diff --git a/addons/test_mail_full/models/test_mail_models.py b/addons/test_mail_full/models/test_mail_models.py
index 02f330d8f26..1d05eab7123 100644
--- a/addons/test_mail_full/models/test_mail_models.py
+++ b/addons/test_mail_full/models/test_mail_models.py
@@ -45,6 +45,7 @@ class MailTestSMSBL(models.Model):
return ['customer_id']
def _sms_get_number_fields(self):
+ # TDE note: should override _phone_get_number_fields but ok as sms in dependencies
return ['phone_nbr', 'mobile_nbr']