[FW][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 X-original-commit odoo/odoo@18cd93ded8 X-original-commit: 94d618ff3ff8ee13d23f893836d00a5a71981938
This commit is contained in:
@@ -152,6 +152,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,
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user