From 3ad1867ea4d7fcda4ccfeb0a7f3d3860b16d389e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 31 Mar 2017 15:31:34 +0200 Subject: [PATCH] [FIX] sales_team: get good team in multi company When getting the default sales team, we could get erroneously the team of another company (either because the use is in a team of another company or the default sales team was in non-bethren company). This fix when searching a sales team: - search only teams the user should see (with access rules) - make default teams "Website Sales" and "Direct Sales" not restricted to one company (and it's ancestors). opw-726461 --- addons/sales_team/data/sales_team_data.xml | 2 ++ addons/sales_team/models/crm_team.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/sales_team/data/sales_team_data.xml b/addons/sales_team/data/sales_team_data.xml index 4ecca9ff36f..0604c8f9205 100644 --- a/addons/sales_team/data/sales_team_data.xml +++ b/addons/sales_team/data/sales_team_data.xml @@ -4,10 +4,12 @@ Direct Sales + Website Sales + diff --git a/addons/sales_team/models/crm_team.py b/addons/sales_team/models/crm_team.py index aa80cfbc511..2eebdd5eceb 100644 --- a/addons/sales_team/models/crm_team.py +++ b/addons/sales_team/models/crm_team.py @@ -19,9 +19,11 @@ class CrmTeam(models.Model): if 'default_team_id' in self.env.context: team_id = self.env['crm.team'].browse(self.env.context.get('default_team_id')) if not team_id or not team_id.exists(): - team_id = self.env['crm.team'].sudo().search( - ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], - limit=1) + company_id = self.sudo(user_id).company_id.id + team_id = self.env['crm.team'].sudo().search([ + '|', ('user_id', '=', user_id), ('member_ids', '=', user_id), + '|', ('company_id', '=', False), ('company_id', 'child_of', [company_id]) + ], limit=1) if not team_id: default_team_id = self.env.ref('sales_team.team_sales_department', raise_if_not_found=False) if default_team_id and (self.env.context.get('default_type') != 'lead' or default_team_id.use_leads):