summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2017-03-31 15:31:34 +0200
committerNicolas Lempereur <nle@odoo.com>2017-04-04 17:57:07 +0200
commit3ad1867ea4d7fcda4ccfeb0a7f3d3860b16d389e (patch)
tree679add4181820966c3ca1c362ea041ffff176273
parent11f0a5c29fad6ecf71c92e20b0b258fe31da06f8 (diff)
[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
-rw-r--r--addons/sales_team/data/sales_team_data.xml2
-rw-r--r--addons/sales_team/models/crm_team.py8
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 @@
<record model="crm.team" id="team_sales_department">
<field name="name">Direct Sales</field>
<field name="member_ids" eval="[(4, ref('base.user_root'))]"/>
+ <field name="company_id" eval="False"/>
</record>
<record model="crm.team" id="salesteam_website_sales">
<field name="name">Website Sales</field>
+ <field name="company_id" eval="False"/>
</record>
</data>
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):