summaryrefslogtreecommitdiff
path: root/addons/crm/tests
diff options
context:
space:
mode:
authorijas ahammed <ija@odoo.com>2020-11-26 11:31:52 +0000
committerThibault Delavallée <tde@odoo.com>2020-12-17 09:10:41 +0000
commit5154f40544e7913f7bcd0ff73f034d111700f580 (patch)
tree96399e5eecab3b1a699d1c889d814da745b7ecdc /addons/crm/tests
parent9b3c4d07b3832bf99c6a9603985b687124fed033 (diff)
[FIX] crm: do not propagate lead phone to partner if formatting differs
With a recent commit[1], we fixed the issue of false warning while changing the partner on lead. But that fix ignored the fact that the lead has an automatic formatting that may lead to false warning. Right way to detect a phone number change is * lead phone is different from partner phone; * lead formatted phone is different from partner formatted phone; If those two conditions are met we are quite sure numbers are different and not only differs in their formatting. In this commit we also fix inverse of phone number. When updating lead phone value we have to use the same heuristic to update partner phone value. That was we avoid unnecessary partner update when only formatting differs. Tests are added to ensure new behavior and that ribbon message is effectively trig erred with correct content. LINKS Task ID-2390287 [1] - https://github.com/odoo/odoo/commit/d29862c1de6208f7fdb7c8104afe0d35241d130b closes odoo/odoo#62397 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Co-authored-by: Ijas Ahammed <ija@odoo.com> Co-authored-by: Thibault Delavallée <tde@odoo.com>
Diffstat (limited to 'addons/crm/tests')
-rw-r--r--addons/crm/tests/test_crm_lead.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py
index 4627e3e33f3..92f7ff638e1 100644
--- a/addons/crm/tests/test_crm_lead.py
+++ b/addons/crm/tests/test_crm_lead.py
@@ -2,7 +2,8 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.crm.tests.common import TestCrmCommon, INCOMING_EMAIL
-from odoo.tests.common import users
+from odoo.addons.phone_validation.tools.phone_validation import phone_format
+from odoo.tests.common import Form, users
class TestCRMLead(TestCrmCommon):
@@ -159,6 +160,57 @@ class TestCRMLead(TestCrmCommon):
self.assertFalse(partner.phone)
@users('user_sales_manager')
+ def test_crm_lead_partner_sync_email_phone(self):
+ """ Specifically test synchronize between a lead and its partner about
+ phone and email fields. Phone especially has some corner cases due to
+ automatic formatting (notably with onchange in form view). """
+ lead, partner = self.lead_1.with_user(self.env.user), self.contact_2
+ lead_form = Form(lead)
+
+ # reset partner phone to a local number
+ partner_phone, partner_email = '202 555 0999', partner.email
+ partner_phone_formatted = phone_format(partner_phone, 'US', '1')
+ partner_phone_sanitized = phone_format(partner_phone, 'US', '1', force_format='E164')
+ self.assertEqual(partner_phone_formatted, '+1 202-555-0999')
+ self.assertEqual(partner_phone_sanitized, '+12025550999')
+ partner.phone = partner_phone
+
+ # email & phone must be automatically set on the lead
+ lead_form.partner_id = partner
+ self.assertEqual(lead_form.email_from, partner_email)
+ self.assertEqual(lead_form.phone, partner_phone_formatted)
+ self.assertFalse(lead_form.ribbon_message)
+
+ lead_form.save()
+ self.assertEqual(partner.phone, partner_phone)
+ self.assertEqual(lead.phone, partner_phone_formatted)
+ self.assertEqual(lead.phone_sanitized, partner_phone_sanitized)
+
+ # writing on the lead field must change the partner field
+ new_email = '"John Zoidberg" <john.zoidberg@test.example.com>'
+ new_email_normalized = 'john.zoidberg@test.example.com'
+ lead_form.email_from = new_email
+ self.assertIn('the customer email will', lead_form.ribbon_message)
+ new_phone = '+1 202 555 7799'
+ new_phone_formatted = phone_format(new_phone, 'US', '1')
+ lead_form.phone = new_phone
+ self.assertEqual(lead_form.phone, new_phone_formatted)
+ self.assertIn('the customer email and phone number will', lead_form.ribbon_message)
+
+ lead_form.save()
+ self.assertEqual(partner.email, new_email)
+ self.assertEqual(partner.email_normalized, new_email_normalized)
+ self.assertEqual(partner.phone, new_phone_formatted)
+
+ # resetting lead values also resets partner
+ lead_form.email_from, lead_form.phone = False, False
+ self.assertIn('the customer email and phone number will', lead_form.ribbon_message)
+ lead_form.save()
+ self.assertFalse(partner.email)
+ self.assertFalse(partner.email_normalized)
+ self.assertFalse(partner.phone)
+
+ @users('user_sales_manager')
def test_crm_lead_stages(self):
lead = self.lead_1.with_user(self.env.user)
self.assertEqual(lead.team_id, self.sales_team_1)