[FIX] crm: handle customer creation on. lead -> oppor. w/ archived lang
To reproduce:
1. enable 'debug' mode
2. go to menu "Settings / Translations / Languages" and enable a new
language (ex: nl_NL)
3 create a new lead and set that language
(IMPORTANT: do not set a customer)
4. go back to menu "Settings / Translations / Languages" and disable the
language you previously enabled at step 2.
5. from the lead list view, selection the lead you created at step 3,
click "Action" and choose "Convert to opportunities"
6. In the wizard choose for:
* Conversion Action: Convert to opportunity
* Customer: Create a new customer
7. Click button "Convert to opportunity"
This crash with the following error:
```
Traceback (most recent call last):
File "/data/build/odoo/odoo/http.py", line 654, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/data/build/odoo/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: Wrong value for res.partner.lang: 'nl_NL'
```
This commit ensure that when converting a lead to an opportunity, we
don't crash if language is archived.
OPW-3617359
closes odoo/odoo#147003
X-original-commit: 208d6ed021f62b1b53f75129a18e8a0d302f47b0
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Xavier Alt (xal) <xal@odoo.com>
This commit is contained in:
@@ -1902,7 +1902,7 @@ class Lead(models.Model):
|
||||
'is_company': is_company,
|
||||
'type': 'contact'
|
||||
}
|
||||
if self.lang_id:
|
||||
if self.lang_id.active:
|
||||
res['lang'] = self.lang_id.code
|
||||
return res
|
||||
|
||||
|
||||
@@ -246,6 +246,27 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon):
|
||||
# TDE FIXME: should take into account normalized email version, not encoded one
|
||||
# self.assertEqual(convert.partner_id, customer)
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_lead_convert_no_lang(self):
|
||||
""" Ensure converting a lead with an archived language correctly falls back on the default partner language. """
|
||||
inactive_lang = self.env["res.lang"].sudo().create({
|
||||
'code': 'en_ZZ',
|
||||
'name': 'Inactive Lang',
|
||||
'active': False,
|
||||
})
|
||||
|
||||
lead = self.lead_1.with_user(self.env.user)
|
||||
lead.lang_id = inactive_lang
|
||||
|
||||
convert = self.env['crm.lead2opportunity.partner'].with_context({
|
||||
'active_model': 'crm.lead',
|
||||
'active_id': self.lead_1.id,
|
||||
'active_ids': self.lead_1.ids,
|
||||
}).create({'action': 'create'})
|
||||
convert.action_apply()
|
||||
self.assertTrue(lead.partner_id)
|
||||
self.assertEqual(lead.partner_id.lang, 'en_US')
|
||||
|
||||
@users('user_sales_manager')
|
||||
def test_lead_convert_internals(self):
|
||||
""" Test internals of convert wizard """
|
||||
|
||||
@@ -112,7 +112,7 @@ class NewLeadNotification(TestCrmCommon):
|
||||
}
|
||||
])
|
||||
expected_list = [
|
||||
(False, self.test_email, None, 'Customer Email', {'lang': 'fr_FR'}),
|
||||
(False, self.test_email, None, 'Customer Email', {'lang': None}),
|
||||
(False, self.test_email, 'en_US', 'Customer Email', {'lang': 'en_US'}),
|
||||
]
|
||||
for lead, expected in zip(leads, expected_list):
|
||||
@@ -121,7 +121,7 @@ class NewLeadNotification(TestCrmCommon):
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0][:4], expected[:4])
|
||||
for partner_fname in expected[4]:
|
||||
found = res[0][4][partner_fname]
|
||||
found = res[0][4].get(partner_fname)
|
||||
expected = expected[4][partner_fname]
|
||||
self.assertEqual(
|
||||
found, expected,
|
||||
|
||||
Reference in New Issue
Block a user