Skip to content

Commit 249ad65

Browse files
committed
[FIX] sales_team_operating_unit: Add default company_id to resolve incompatible records error coming up while creating sales team, when a user doesn't have multicompany access while creating sales team
1 parent 8a6ec74 commit 249ad65

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

sales_team_operating_unit/models/crm_team.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2017-TODAY Serpent Consulting Services Pvt. Ltd.
33
# (<http://www.serpentcs.com>)
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
5-
from odoo import fields, models
5+
from odoo import api, fields, models
66

77

88
class CrmTeam(models.Model):
@@ -13,3 +13,11 @@ class CrmTeam(models.Model):
1313
default=lambda self: self.env["res.users"]._get_default_operating_unit(),
1414
check_company=True,
1515
)
16+
17+
@api.model
18+
def default_get(self, fields_list):
19+
res = super().default_get(fields_list)
20+
if res.get("operating_unit_id"):
21+
operating_unit = self.env["operating.unit"].browse(res["operating_unit_id"])
22+
res["company_id"] = operating_unit.company_id.id
23+
return res

sales_team_operating_unit/tests/test_crm_team_operating_unit.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2017-TODAY Serpent Consulting Services Pvt. Ltd.
33
# (<http://www.serpentcs.com>)
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
5-
from odoo.tests import common
5+
from odoo.tests import Form, common
66

77

88
class TestSaleTeamOperatingUnit(common.TransactionCase):
@@ -68,6 +68,18 @@ def _create_crm_team(cls, uid, operating_unit):
6868
def test_crm_team(self):
6969
# User 2 is only assigned to B2C Operating Unit, and cannot
7070
# access CRM teams for Main Operating Unit.
71+
72+
with Form(
73+
self.crm_team_model, view="sales_team.crm_team_view_form"
74+
) as crm_form:
75+
crm_form.name = "Test CRM Team"
76+
crm_form.operating_unit_id = self.ou1
77+
self.assertEqual(
78+
crm_form.company_id,
79+
self.ou1.company_id,
80+
"Company should be same as Operating Unit company",
81+
)
82+
7183
team = self.crm_team_model.with_user(self.user2.id).search(
7284
[("id", "=", self.team1.id), ("operating_unit_id", "=", self.ou1.id)]
7385
)

0 commit comments

Comments
 (0)