From c4b0bcbbd52d904bd5b1ed2b7a0fc9f2edfaa314 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Tue, 18 Feb 2020 10:31:51 +0000 Subject: [PATCH] [FIX] sale: Unpredictable sales team Steps to reproduce the bug: - Install website_crm_score - Add Mitchell Admin in 2 sales teams - Create a quote - Play with the ordering of sales teams sequences Bug: The default sales team will be different at quote creation, partner selection, etc. and will basically be unpredictable (while you would expect it to take the first team the salesperson is a member of in the order of the sequence) The problem is an inconsistent use of the _get_default_team_id method and the sales team of a user. Since the website score module add the possibility to have a user member of more than one team, using the team of the user is bad. You should use the method all the time for consistent results. opw:2196934 closes odoo/odoo#45718 X-original-commit: 6d7bbd3074e6b3771b582bf544624cef59e1c6a3 Signed-off-by: Simon Goffin (sig) --- addons/sale/models/sale.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 93742486b71..e2fe110f2aa 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -361,14 +361,13 @@ class SaleOrder(models.Model): if self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company.invoice_terms: values['note'] = self.with_context(lang=self.partner_id.lang).env.company.invoice_terms - # Use team of salesman if any otherwise leave as-is - values['team_id'] = partner_user.team_id.id if partner_user and partner_user.team_id else self.team_id + values['team_id'] = self.env['crm.team']._get_default_team_id(user_id=user_id) self.update(values) @api.onchange('user_id') def onchange_user_id(self): - if self.user_id and self.user_id.sale_team_id: - self.team_id = self.user_id.sale_team_id + if self.user_id: + self.team_id = self.env['crm.team']._get_default_team_id(user_id=self.user_id.id) @api.onchange('partner_id') def onchange_partner_id_warning(self):