[FIX] crm: use default_lang in contact creation only for active language

Expected Behaviour
When creating a contact from a lead with an unactive language, Odoo should
replace this language with the parent's language or the DB language.

Observed Behaviour
Since saas-15.1, when you create a contact from a lead email adress,
the contact is created with the lead's language, even if it's not active,
which give an error.

Reproducibility
This bug can be reproduced following these steps:
1. Set an uninstalled language on a lead (two choices):
a. Select an uninstalled language on a lead (this is what happens with
the trial creation, and how to reproduce it via the interface)
- install 8 languages in order to activate the "Search More..." link in
the Language select field of a lead
- on a lead which doesn't have a Customer yet, in the Language, "Search
More...", filter with Active = False, and select an uninstalled language
b. Install a language, select it on a lead with no Customer, and uninstall
the language
2. On the lead, in its chatter, open the Send Message and check the checkbox
next to its email => it should open a popup
3. Validate the popup => there is an exception in saas-15.X, and not in 15.0.

Related Issues/PR
- opw-2745841

closes odoo/odoo#85992

X-original-commit: c9b6ec91a87a4ad007287d978adc34332a97f8da
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
anhe-odoo
2022-03-09 15:18:57 +00:00
parent 3cf5044e31
commit 1d2447c30e
2 changed files with 40 additions and 2 deletions
+4 -2
View File
@@ -1804,12 +1804,14 @@ class Lead(models.Model):
recipients = super(Lead, self)._message_get_suggested_recipients()
try:
for lead in self:
# check if that language is correctly installed (and active) before using it
lang_code = lead.lang_code if lead.lang_code and self.env['res.lang']._lang_get(lead.lang_code) else None
if lead.partner_id:
lead._message_add_suggested_recipient(
recipients, partner=lead.partner_id, lang=lead.lang_code, reason=_('Customer'))
recipients, partner=lead.partner_id, lang=lang_code, reason=_('Customer'))
elif lead.email_from:
lead._message_add_suggested_recipient(
recipients, email=lead.email_from, lang=lead.lang_code, reason=_('Customer Email'))
recipients, email=lead.email_from, lang=lang_code, reason=_('Customer Email'))
except AccessError: # no read access rights -> just ignore suggested recipients because this imply modifying followers
pass
return recipients
+36
View File
@@ -543,6 +543,42 @@ class TestCRMLead(TestCrmCommon):
self.assertEqual(new_lead.partner_id.email, 'unknown.sender@test.example.com')
self.assertEqual(new_lead.partner_id.team_id, self.sales_team_1)
@users('user_sales_manager')
def test_message_get_suggested_recipients(self):
"""This test checks that creating a contact from a lead with an inactive language will ignore the language
while creating a contact from a lead with an active language will take it into account """
ResLang = self.env['res.lang'].sudo().with_context(active_test=False)
# Create a lead with an inactive language -> should ignore the preset language
lang_fr = ResLang.search([('code', '=', 'fr_FR')])
if not lang_fr:
lang_fr = ResLang._create_lang('fr_FR')
# set French language as inactive then try to call "_message_get_suggested_recipients"
# -> lang code should be ignored
lang_fr.active = False
lead1 = self.env['crm.lead'].create({
'name': 'TestLead',
'email_from': self.test_email,
'lang_id': lang_fr.id,
})
data = lead1._message_get_suggested_recipients()[lead1.id]
self.assertEqual(data, [(False, self.test_email, None, 'Customer Email')])
# Create a lead with an active language -> should keep the preset language for recipients
lang_en = ResLang.search([('code', '=', 'en_US')])
if not lang_en:
lang_en = ResLang._create_lang('en_US')
# set American English language as active then try to call "_message_get_suggested_recipients"
# -> lang code should be kept
lang_en.active = True
lead2 = self.env['crm.lead'].create({
'name': 'TestLead',
'email_from': self.test_email,
'lang_id': lang_en.id,
})
data = lead2._message_get_suggested_recipients()[lead2.id]
self.assertEqual(data, [(False, self.test_email, "en_US", 'Customer Email')])
@users('user_sales_manager')
def test_phone_mobile_search(self):
lead_1 = self.env['crm.lead'].create({