[FIX] sales_team: better support default_team_id
Purpose of this commit is to better support default_team_id in context when computing default team. Indeed currently default key is ignored if the user is member or responsible of any team. It is used only when no membership exists as a fallback. However when giving a default_team_id in a default-like method we think we should better try to match this value. When having memberships the final team is the default one if present in the subset of teams. Instead of taking the first found one in the teams set (filtered on a domain or not) we first check for the default team presence, then fallback on the ordering based on sequence. Task-2852947 opw-2830913 X-original-commit: fb060c86daf0c1d737abc9228002cdfa280e1d2c Part-of: odoo/odoo#94045
This commit is contained in:
@@ -25,13 +25,16 @@ class CrmTeam(models.Model):
|
||||
method is not called by default_get as it takes some additional
|
||||
parameters and is meant to be called by other default methods.
|
||||
|
||||
Heuristic (when multiple match: take first sequence ordered)
|
||||
Heuristic (when multiple match: take from default context value or first
|
||||
sequence ordered)
|
||||
|
||||
1- any of my teams (member OR responsible) matching domain
|
||||
2- any of my teams (member OR responsible)
|
||||
1- any of my teams (member OR responsible) matching domain, either from
|
||||
context or based on _order;
|
||||
2- any of my teams (member OR responsible), either from context or based
|
||||
on _order;
|
||||
3- default from context
|
||||
4- any team matching my company and domain
|
||||
5- any team matching my company
|
||||
4- any team matching my company and domain (based on company rule)
|
||||
5- any team matching my company (based on company rule)
|
||||
|
||||
Note: ResPartner.team_id field is explicitly not taken into account. We
|
||||
think this field causes a lot of noises compared to its added value.
|
||||
@@ -45,6 +48,9 @@ class CrmTeam(models.Model):
|
||||
user = self.env.user
|
||||
else:
|
||||
user = self.env['res.users'].sudo().browse(user_id)
|
||||
default_team = self.env['crm.team'].browse(
|
||||
self.env.context['default_team_id']
|
||||
) if self.env.context.get('default_team_id') else self.env['crm.team']
|
||||
valid_cids = [False] + [c for c in user.company_ids.ids if c in self.env.companies.ids]
|
||||
|
||||
# 1- find in user memberships - note that if current user in C1 searches
|
||||
@@ -55,20 +61,28 @@ class CrmTeam(models.Model):
|
||||
'|', ('user_id', '=', user.id), ('member_ids', 'in', [user.id])
|
||||
])
|
||||
if teams and domain:
|
||||
team = teams.filtered_domain(domain)[:1]
|
||||
filtered_teams = teams.filtered_domain(domain)
|
||||
if default_team and default_team in filtered_teams:
|
||||
team = default_team
|
||||
else:
|
||||
team = filtered_teams[:1]
|
||||
# 2- any of my teams
|
||||
if not team:
|
||||
team = teams[:1]
|
||||
if default_team and default_team in teams:
|
||||
team = default_team
|
||||
else:
|
||||
team = teams[:1]
|
||||
|
||||
# 3- default: context
|
||||
if not team and 'default_team_id' in self.env.context:
|
||||
team = self.env['crm.team'].browse(self.env.context.get('default_team_id'))
|
||||
if not team and default_team:
|
||||
team = default_team
|
||||
|
||||
# 4- default: first one matching domain, then first one
|
||||
if not team:
|
||||
teams = self.env['crm.team'].search([('company_id', 'in', valid_cids)])
|
||||
# 4- default: based on company rule, first one matching domain
|
||||
if teams and domain:
|
||||
team = teams.filtered_domain(domain)[:1]
|
||||
# 5- default: based on company rule, first one
|
||||
if not team:
|
||||
team = teams[:1]
|
||||
|
||||
|
||||
@@ -125,8 +125,8 @@ class TestDefaultTeam(TestSalesCommon):
|
||||
default_team_id=self.sales_team_1.id
|
||||
)._get_default_team_id()
|
||||
self.assertEqual(
|
||||
team, self.team_sequence,
|
||||
'SalesTeam: default not taken into account if member / responsible'
|
||||
team, self.sales_team_1,
|
||||
'SalesTeam: default takes over ordering when member / responsible'
|
||||
)
|
||||
|
||||
# remove all memberships
|
||||
|
||||
Reference in New Issue
Block a user