[FIX] crm, sales_team: compute company within allowed_company_ids
Steps to follow
- Select only one company in the company selector but not the default one
from the current user;
- Go the the CRM app;
- Create a lead;
-> A multi company error appears !
Solution
- The default team is now restricted to the companies in the context
- When computing a lead's company_id when the team has no company, keep only
the ones within the allowed_company_ids;
opw-2713757
closes odoo/odoo#83764
X-original-commit: 58b9b3e839c7725fdcd66376564ce6554a4b82ac
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
db353f94d0
commit
e5f35a6074
@@ -295,8 +295,10 @@ class Lead(models.Model):
|
|||||||
|
|
||||||
# propose a new company based on responsible, limited by team
|
# propose a new company based on responsible, limited by team
|
||||||
if not proposal:
|
if not proposal:
|
||||||
if lead.user_id:
|
if lead.user_id and lead.team_id.company_id:
|
||||||
proposal = lead.team_id.company_id or lead.user_id.company_id
|
proposal = lead.team_id.company_id
|
||||||
|
elif lead.user_id:
|
||||||
|
proposal = lead.user_id.company_id & self.env.companies
|
||||||
elif lead.team_id:
|
elif lead.team_id:
|
||||||
proposal = lead.team_id.company_id
|
proposal = lead.team_id.company_id
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -101,20 +101,20 @@ class TestCRMLeadMultiCompany(TestCrmCommon):
|
|||||||
lead = LeadUnsyncCids.sudo().create({
|
lead = LeadUnsyncCids.sudo().create({
|
||||||
'name': 'My Lead MC',
|
'name': 'My Lead MC',
|
||||||
})
|
})
|
||||||
self.assertEqual(lead.company_id, self.company_2)
|
self.assertFalse(lead.company_id,
|
||||||
self.assertEqual(lead.team_id, self.team_company2)
|
'Lead: due to MC rule, avoid setting a company when it would cause crashes')
|
||||||
# self.assertEqual(lead.team_id, self.sales_team_1,
|
self.assertEqual(lead.team_id, self.sales_team_1,
|
||||||
# 'Lead: due to MC rule, took first availability in other company')
|
'Lead: due to MC rule, took first availability in other company')
|
||||||
self.assertEqual(lead.user_id, self.user_sales_manager_mc)
|
self.assertEqual(lead.user_id, self.user_sales_manager_mc)
|
||||||
|
|
||||||
# multicompany raises if trying to create manually
|
# manual creation
|
||||||
with self.assertRaises(AccessError):
|
lead = LeadUnsyncCids.create({
|
||||||
lead = LeadUnsyncCids.create({
|
'name': 'My Lead MC',
|
||||||
'name': 'My Lead MC',
|
})
|
||||||
})
|
self.assertFalse(lead.company_id,
|
||||||
# self.assertEqual(lead.company_id.id, False)
|
'Lead: due to MC rule, avoid setting a company when it would cause crashes')
|
||||||
# self.assertEqual(lead.team_id, self.sales_team_1)
|
self.assertEqual(lead.team_id, self.sales_team_1)
|
||||||
# self.assertEqual(lead.user_id, self.user_sales_manager_mc)
|
self.assertEqual(lead.user_id, self.user_sales_manager_mc)
|
||||||
|
|
||||||
@users('user_sales_manager_mc')
|
@users('user_sales_manager_mc')
|
||||||
def test_lead_mc_company_form(self):
|
def test_lead_mc_company_form(self):
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class CrmTeam(models.Model):
|
|||||||
user = self.env.user
|
user = self.env.user
|
||||||
else:
|
else:
|
||||||
user = self.env['res.users'].sudo().browse(user_id)
|
user = self.env['res.users'].sudo().browse(user_id)
|
||||||
valid_cids = [False] + user.company_ids.ids
|
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
|
# 1- find in user memberships - note that if current user in C1 searches
|
||||||
# for team belonging to a user in C1/C2 -> only results for C1 will be returned
|
# for team belonging to a user in C1/C2 -> only results for C1 will be returned
|
||||||
|
|||||||
Reference in New Issue
Block a user