Skip to content

Commit a77390c

Browse files
lade-odootde-banana-odoo
authored andcommitted
[FIX] crm: set partner company on lead when resetting company
In a multi-company environment, when we transform a lead (which has no salesperson) into an opportunity, we get an error if the customer has a company set. To reproduce the issue 1) Create a new company 2) Create a Lead for a customer with the Company set 3) Remove the Sales Team 4) Set the company on the Lead 5) Convert to an opportunity and you will see an error showing up Solution A previous commit (1fad826) adapted the `_compute_company_id` computation in which a case was forgotten (the case described here-above). The fix was to force the `company_id` to the one of the `partner_id` if it has one. OPW-2805181 Task-2888330 closes odoo#88108 Signed-off-by: Thibault Delavallee (tde) <[email protected]> X-original-commit: fc3bb66
1 parent c40c8df commit a77390c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

addons/crm/models/crm_lead.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _compute_team_id(self):
272272
team = self.env['crm.team']._get_default_team_id(user_id=user.id, domain=team_domain)
273273
lead.team_id = team.id
274274

275-
@api.depends('user_id', 'team_id')
275+
@api.depends('user_id', 'team_id', 'partner_id')
276276
def _compute_company_id(self):
277277
""" Compute company_id coherency. """
278278
for lead in self:
@@ -290,7 +290,9 @@ def _compute_company_id(self):
290290
if lead.team_id and not lead.team_id.company_id and not lead.user_id:
291291
proposal = False
292292
# no user and no team -> void company and let assignment do its job
293-
if not lead.team_id and not lead.user_id:
293+
# unless customer has a company
294+
if not lead.team_id and not lead.user_id and \
295+
(not lead.partner_id or lead.partner_id.company_id != proposal):
294296
proposal = False
295297

296298
# propose a new company based on responsible, limited by team
@@ -301,6 +303,8 @@ def _compute_company_id(self):
301303
proposal = lead.user_id.company_id & self.env.companies
302304
elif lead.team_id:
303305
proposal = lead.team_id.company_id
306+
elif lead.partner_id:
307+
proposal = lead.partner_id.company_id
304308
else:
305309
proposal = False
306310

addons/test_crm_full/tests/test_performance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_lead_create_form_address(self):
8989
@warmup
9090
def test_lead_create_form_partner(self):
9191
""" Test a single lead creation using Form with a partner """
92-
with freeze_time(self.reference_now), self.assertQueryCount(user_sales_leads=193): # tcf only: 178 - com runbot: 179/180
92+
with freeze_time(self.reference_now), self.assertQueryCount(user_sales_leads=197): # tcf only: 178 - com runbot: 179/180
9393
self.env.cr._now = self.reference_now # force create_date to check schedulers
9494
with Form(self.env['crm.lead']) as lead_form:
9595
lead_form.partner_id = self.partners[0]

0 commit comments

Comments
 (0)