[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) <sig@openerp.com>
This commit is contained in:
Damien Bouvy
2020-02-19 13:14:20 +00:00
committed by Goffin Simon
parent 7e47742225
commit c4b0bcbbd5
+3 -4
View File
@@ -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):