[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:
Hubert Van de Walle
2022-02-01 14:37:54 +00:00
committed by Thibault Delavallée
parent db353f94d0
commit e5f35a6074
3 changed files with 17 additions and 15 deletions
+4 -2
View File
@@ -295,8 +295,10 @@ class Lead(models.Model):
# propose a new company based on responsible, limited by team
if not proposal:
if lead.user_id:
proposal = lead.team_id.company_id or lead.user_id.company_id
if lead.user_id and lead.team_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:
proposal = lead.team_id.company_id
else:
+12 -12
View File
@@ -101,20 +101,20 @@ class TestCRMLeadMultiCompany(TestCrmCommon):
lead = LeadUnsyncCids.sudo().create({
'name': 'My Lead MC',
})
self.assertEqual(lead.company_id, self.company_2)
self.assertEqual(lead.team_id, self.team_company2)
# self.assertEqual(lead.team_id, self.sales_team_1,
# 'Lead: due to MC rule, took first availability in other company')
self.assertFalse(lead.company_id,
'Lead: due to MC rule, avoid setting a company when it would cause crashes')
self.assertEqual(lead.team_id, self.sales_team_1,
'Lead: due to MC rule, took first availability in other company')
self.assertEqual(lead.user_id, self.user_sales_manager_mc)
# multicompany raises if trying to create manually
with self.assertRaises(AccessError):
lead = LeadUnsyncCids.create({
'name': 'My Lead MC',
})
# self.assertEqual(lead.company_id.id, False)
# self.assertEqual(lead.team_id, self.sales_team_1)
# self.assertEqual(lead.user_id, self.user_sales_manager_mc)
# manual creation
lead = LeadUnsyncCids.create({
'name': 'My Lead MC',
})
self.assertFalse(lead.company_id,
'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.user_id, self.user_sales_manager_mc)
@users('user_sales_manager_mc')
def test_lead_mc_company_form(self):
+1 -1
View File
@@ -45,7 +45,7 @@ class CrmTeam(models.Model):
user = self.env.user
else:
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
# for team belonging to a user in C1/C2 -> only results for C1 will be returned