Skip to content

Commit d969724

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]>
1 parent bcdbbae commit d969724

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

addons/crm/models/crm_lead.py

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

271-
@api.depends('user_id', 'team_id')
271+
@api.depends('user_id', 'team_id', 'partner_id')
272272
def _compute_company_id(self):
273273
""" Compute company_id coherency. """
274274
for lead in self:
@@ -286,7 +286,9 @@ def _compute_company_id(self):
286286
if lead.team_id and not lead.team_id.company_id and not lead.user_id:
287287
proposal = False
288288
# no user and no team -> void company and let assignment do its job
289-
if not lead.team_id and not lead.user_id:
289+
# unless customer has a company
290+
if not lead.team_id and not lead.user_id and \
291+
(not lead.partner_id or lead.partner_id.company_id != proposal):
290292
proposal = False
291293

292294
# propose a new company based on responsible, limited by team
@@ -297,6 +299,8 @@ def _compute_company_id(self):
297299
proposal = lead.user_id.company_id & self.env.companies
298300
elif lead.team_id:
299301
proposal = lead.team_id.company_id
302+
elif lead.partner_id:
303+
proposal = lead.partner_id.company_id
300304
else:
301305
proposal = False
302306

0 commit comments

Comments
 (0)