[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
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user