[FIX] crm: convert values given to computed fields
Followup of 9c9f477f04e8f4ee9b18092fe894890c2ab31b58 and f8179007f9aa662be7318edeb18426ea1c906c15 In some cases (notably event_crm addon in 13.4) a country record is propagated instead of a country ID; converting as write values ensure we always deal with IDs in all cases. Also add some tests to cover more test cases. Notably phone and email behavior in 13.3 compared to other fields. For example phone is kept is partner's phone is void. It may leads to inconsistencies (partner US, Belgian phone number). We think it is better to keep values and let salesmen change them than voiding values customer gave. PR #55390 Task ID-2311981 closes odoo/odoo#55412 X-original-commit: a26735f516e48acb77e234862e17e29be71d7d1d Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -442,7 +442,7 @@ class Lead(models.Model):
|
||||
'partner_name': partner_name or self.partner_name,
|
||||
'contact_name': False if partner.is_company else partner.name or self.contact_name,
|
||||
})
|
||||
return values
|
||||
return self._convert_to_write(values)
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# ORM
|
||||
|
||||
@@ -7,6 +7,34 @@ from odoo.tests.common import users
|
||||
|
||||
class TestCRMLead(TestCrmCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCRMLead, cls).setUpClass()
|
||||
cls.country_ref = cls.env.ref('base.be')
|
||||
cls.test_email = '"Test Email" <test.email@example.com>'
|
||||
cls.test_phone = '0485112233'
|
||||
|
||||
@users('user_sales_leads')
|
||||
def test_crm_lead_creation_no_partner(self):
|
||||
lead_data = {
|
||||
'name': 'Test',
|
||||
'country_id': self.country_ref.id,
|
||||
'email_from': self.test_email,
|
||||
'phone': self.test_phone,
|
||||
}
|
||||
lead = self.env['crm.lead'].new(lead_data)
|
||||
# get the street should not trigger cache miss
|
||||
lead.street
|
||||
# Create the lead and the write partner_id = False: country should remain
|
||||
lead = self.env['crm.lead'].create(lead_data)
|
||||
self.assertEqual(lead.country_id, self.country_ref, "Country should be set on the lead")
|
||||
self.assertEqual(lead.email_from, self.test_email)
|
||||
self.assertEqual(lead.phone, self.test_phone)
|
||||
lead.partner_id = False
|
||||
self.assertEqual(lead.country_id, self.country_ref, "Country should still be set on the lead")
|
||||
self.assertEqual(lead.email_from, self.test_email)
|
||||
self.assertEqual(lead.phone, self.test_phone)
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_crm_lead_creation_partner(self):
|
||||
lead = self.env['crm.lead'].create({
|
||||
@@ -31,42 +59,23 @@ class TestCRMLead(TestCrmCommon):
|
||||
self.assertEqual(lead.zip, self.contact_1.zip)
|
||||
self.assertEqual(lead.country_id, self.contact_1.country_id)
|
||||
|
||||
def test_crm_lead_creation_no_partner(self):
|
||||
belgium = self.env.ref('base.be')
|
||||
lead_data = {
|
||||
'name': 'Test',
|
||||
'country_id': belgium.id,
|
||||
'email_from': 'test@odoo.com',
|
||||
'phone': '04584579646',
|
||||
}
|
||||
lead = self.env['crm.lead'].new(lead_data)
|
||||
# get the street should not trigger cache miss
|
||||
lead.street
|
||||
# Create the lead and the write partner_id = False
|
||||
# Country should remain
|
||||
lead = self.env['crm.lead'].create(lead_data)
|
||||
self.assertEqual(lead.country_id, belgium, "Country should be set on the lead")
|
||||
lead.partner_id = False
|
||||
self.assertEqual(lead.country_id, belgium, "Country should still be set on the lead")
|
||||
|
||||
def test_crm_lead_creation_partner_no_info(self):
|
||||
belgium = self.env.ref('base.be')
|
||||
empty_partner = self.env['res.partner'].create({
|
||||
'name': 'Empty partner',
|
||||
'is_company': True
|
||||
})
|
||||
lead_data = {
|
||||
'name': 'Test',
|
||||
'country_id': belgium.id,
|
||||
'email_from': 'test@odoo.com',
|
||||
'phone': '04584579646',
|
||||
'country_id': self.country_ref.id,
|
||||
'email_from': self.test_email,
|
||||
'phone': self.test_phone,
|
||||
}
|
||||
lead = self.env['crm.lead'].create(lead_data)
|
||||
lead.partner_id = empty_partner
|
||||
self.assertEqual(bool(lead.country_id), False, "Country should be empty")
|
||||
self.assertEqual(lead.country_id, self.env['res.country'], "Country should be empty")
|
||||
self.assertEqual(lead.contact_name, False, "Contact name should be empty")
|
||||
self.assertEqual(lead.email_from, lead_data['email_from'], "Email From should keep its initial value")
|
||||
self.assertEqual(lead.phone, lead_data['phone'], "Phone should keep its initial value")
|
||||
self.assertEqual(lead.email_from, self.test_email, "Email From should keep its initial value")
|
||||
self.assertEqual(lead.phone, self.test_phone, "Phone should keep its initial value")
|
||||
self.assertEqual(lead.partner_name, empty_partner.name, "Partner name should be set as contact is a company")
|
||||
|
||||
@users('user_sales_manager')
|
||||
@@ -111,6 +120,40 @@ class TestCRMLead(TestCrmCommon):
|
||||
self.assertEqual(lead.probability, 100.0)
|
||||
self.assertEqual(lead.stage_id, self.stage_gen_won) # generic won stage has lower sequence than team won stage
|
||||
|
||||
@users('user_sales_leads')
|
||||
def test_crm_lead_update_contact(self):
|
||||
# ensure initial data, especially for corner cases
|
||||
self.assertFalse(self.contact_company_1.phone)
|
||||
self.assertEqual(self.contact_company_1.country_id.code, "US")
|
||||
lead = self.env['crm.lead'].create({
|
||||
'name': 'Test',
|
||||
'country_id': self.country_ref.id,
|
||||
'email_from': self.test_email,
|
||||
'phone': self.test_phone,
|
||||
})
|
||||
self.assertEqual(lead.country_id, self.country_ref, "Country should be set on the lead")
|
||||
lead.partner_id = False
|
||||
self.assertEqual(lead.country_id, self.country_ref, "Country should still be set on the lead")
|
||||
self.assertEqual(lead.email_from, self.test_email)
|
||||
self.assertEqual(lead.phone, self.test_phone)
|
||||
self.assertEqual(lead.email_state, 'correct')
|
||||
self.assertEqual(lead.phone_state, 'correct')
|
||||
|
||||
lead.partner_id = self.contact_company_1
|
||||
self.assertEqual(lead.country_id, self.contact_company_1.country_id, "Country should still be the one set on partner")
|
||||
self.assertEqual(lead.email_from, self.contact_company_1.email)
|
||||
self.assertEqual(lead.phone, self.test_phone)
|
||||
self.assertEqual(lead.email_state, 'correct')
|
||||
# currently we keep phone as partner as a void one -> may lead to inconsistencies
|
||||
self.assertEqual(lead.phone_state, 'incorrect', "Belgian phone with US country -> considered as incorrect")
|
||||
|
||||
lead.email_from = 'broken'
|
||||
lead.phone = 'alsobroken'
|
||||
self.assertEqual(lead.email_state, 'incorrect')
|
||||
self.assertEqual(lead.phone_state, 'incorrect')
|
||||
self.assertEqual(self.contact_company_1.email, 'broken')
|
||||
self.assertEqual(self.contact_company_1.phone, 'alsobroken')
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_crm_team_alias(self):
|
||||
new_team = self.env['crm.team'].create({
|
||||
|
||||
Reference in New Issue
Block a user