Skip to content

Commit 51ed1cc

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 ac9b6ef commit 51ed1cc

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
@@ -271,7 +271,7 @@ def _compute_team_id(self):
271271
team = self.env['crm.team']._get_default_team_id(user_id=user.id, domain=team_domain)
272272
lead.team_id = team.id
273273

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

295297
# propose a new company based on responsible, limited by team
@@ -300,6 +302,8 @@ def _compute_company_id(self):
300302
proposal = lead.user_id.company_id & self.env.companies
301303
elif lead.team_id:
302304
proposal = lead.team_id.company_id
305+
elif lead.partner_id:
306+
proposal = lead.partner_id.company_id
303307
else:
304308
proposal = False
305309

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: 180 - com runbot: 180
92+
with freeze_time(self.reference_now), self.assertQueryCount(user_sales_leads=197): # tcf only: 180 - com runbot: 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)