summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2021-02-02 12:36:06 +0000
committerThibault Delavallée <tde@odoo.com>2021-02-05 10:25:16 +0000
commit18cd93ded85d2e62a7839504d6e199859a24344c (patch)
treed35c933084438e3e25093fc5e103472b00a2ea3a
parent0182aa1b536244e84f4d3474b6b9f5c3a259ca1e (diff)
[IMP] crm: add tests about lead / partner synchronization and computed fields
Add tests related to lead / partner contact fields synchronization. Add tests with user input and/or partner synchronization to ensure editable stored fields work as expected on lead model. Warning: those tests are failing. Next commit will split computed fields into several methods in order to fix computation. LINKS COM PR odoo/odoo#65381 Task ID-2451339
-rw-r--r--addons/crm/tests/common.py2
-rw-r--r--addons/crm/tests/test_crm_lead.py49
2 files changed, 51 insertions, 0 deletions
diff --git a/addons/crm/tests/common.py b/addons/crm/tests/common.py
index f46e1fd265f..5e8e18251d4 100644
--- a/addons/crm/tests/common.py
+++ b/addons/crm/tests/common.py
@@ -131,6 +131,8 @@ class TestCrmCommon(TestSalesCommon, MailCase):
'name': 'Philip J Fry',
'email': 'philip.j.fry@test.example.com',
'mobile': '+1 202 555 0122',
+ 'title': cls.env.ref('base.res_partner_title_mister').id,
+ 'function': 'Delivery Boy',
'phone': False,
'parent_id': cls.contact_company_1.id,
'is_company': False,
diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py
index 92f7ff638e1..8897aa3e845 100644
--- a/addons/crm/tests/test_crm_lead.py
+++ b/addons/crm/tests/test_crm_lead.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo.addons.crm.models.crm_lead import PARTNER_FIELDS_TO_SYNC, PARTNER_ADDRESS_FIELDS_TO_SYNC
from odoo.addons.crm.tests.common import TestCrmCommon, INCOMING_EMAIL
from odoo.addons.phone_validation.tools.phone_validation import phone_format
from odoo.tests.common import Form, users
@@ -15,6 +16,54 @@ class TestCRMLead(TestCrmCommon):
cls.test_email = '"Test Email" <test.email@example.com>'
cls.test_phone = '0485112233'
+ def assertLeadAddress(self, lead, street, street2, city, lead_zip, state, country):
+ self.assertEqual(lead.street, street)
+ self.assertEqual(lead.street2, street2)
+ self.assertEqual(lead.city, city)
+ self.assertEqual(lead.zip, lead_zip)
+ self.assertEqual(lead.state_id, state)
+ self.assertEqual(lead.country_id, country)
+
+ @users('user_sales_leads')
+ def test_crm_lead_contact_fields_mixed(self):
+ """ Test mixed configuration from partner: both user input and coming
+ from partner, in order to ensure we do not loose information or make
+ it incoherent. """
+ lead_data = {
+ 'name': 'TestMixed',
+ 'partner_id': self.contact_1.id,
+ # address
+ 'country_id': self.country_ref.id,
+ # other contact fields
+ 'function': 'Parmesan Rappeur',
+ # specific contact fields
+ 'email_from': self.test_email,
+ 'phone': self.test_phone,
+ }
+ lead = self.env['crm.lead'].create(lead_data)
+ # classic
+ self.assertEqual(lead.name, "TestMixed")
+ # address
+ self.assertLeadAddress(lead, False, False, False, False, self.env['res.country.state'], self.country_ref)
+ # other contact fields
+ for fname in set(PARTNER_FIELDS_TO_SYNC) - set(['function']):
+ self.assertEqual(lead[fname], self.contact_1[fname], 'No user input -> take from contact for field %s' % fname)
+ self.assertEqual(lead.function, 'Parmesan Rappeur', 'User input should take over partner value')
+ # specific contact fields
+ self.assertEqual(lead.partner_name, self.contact_company_1.name)
+ self.assertEqual(lead.contact_name, self.contact_1.name)
+ self.assertEqual(lead.email_from, self.test_email)
+ self.assertEqual(lead.phone, self.test_phone)
+
+ # update a single address fields -> only those are updated
+ lead.write({'street': 'Super Street', 'city': 'Super City'})
+ self.assertLeadAddress(lead, 'Super Street', False, 'Super City', False, self.env['res.country.state'], self.country_ref)
+
+ # change partner -> whole address updated
+ lead.write({'partner_id': self.contact_company_1.id})
+ for fname in PARTNER_ADDRESS_FIELDS_TO_SYNC:
+ self.assertEqual(lead[fname], self.contact_company_1[fname])
+
@users('user_sales_leads')
def test_crm_lead_creation_no_partner(self):
lead_data = {