Skip to content

Commit

Permalink
[MIG] sales_team_operating_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alan196 committed Jul 27, 2023
1 parent e5d7553 commit f2491fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sales_team_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Sales Team Operating Unit",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "ForgeFlow, SerpentCS, Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/operating-unit",
Expand Down
43 changes: 23 additions & 20 deletions sales_team_operating_unit/tests/test_crm_team_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,40 @@


class TestSaleTeamOperatingUnit(common.TransactionCase):
def setUp(self):
super(TestSaleTeamOperatingUnit, self).setUp()
self.res_users_model = self.env["res.users"].with_context(
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.res_users_model = cls.env["res.users"].with_context(
tracking_disable=True, no_reset_password=True
)
self.crm_team_model = self.env["crm.team"]
cls.crm_team_model = cls.env["crm.team"]
# Groups
self.grp_sale_mngr = self.env.ref("sales_team.group_sale_manager")
self.grp_user = self.env.ref("operating_unit.group_multi_operating_unit")
cls.grp_sale_mngr = cls.env.ref("sales_team.group_sale_manager")
cls.grp_user = cls.env.ref("operating_unit.group_multi_operating_unit")
# Company
self.company = self.env.ref("base.main_company")
cls.company = cls.env.ref("base.main_company")
# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
cls.ou1 = cls.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
self.b2c = self.env.ref("operating_unit.b2c_operating_unit")
cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit")
# Create User 1 with Main OU

self.user1 = self._create_user(
"user_1", [self.grp_sale_mngr, self.grp_user], self.company, [self.ou1]
cls.user1 = cls._create_user(
"user_1", [cls.grp_sale_mngr, cls.grp_user], cls.company, [cls.ou1]
)
# Create User 2 with B2C OU
self.user2 = self._create_user(
"user_2", [self.grp_sale_mngr, self.grp_user], self.company, [self.b2c]
cls.user2 = cls._create_user(
"user_2", [cls.grp_sale_mngr, cls.grp_user], cls.company, [cls.b2c]
)
# Create CRM teams
self.team1 = self._create_crm_team(self.user1.id, self.ou1)
self.team2 = self._create_crm_team(self.user2.id, self.b2c)
cls.team1 = cls._create_crm_team(cls.user1.id, cls.ou1)
cls.team2 = cls._create_crm_team(cls.user2.id, cls.b2c)

def _create_user(self, login, groups, company, operating_units, context=None):
@classmethod
def _create_user(cls, login, groups, company, operating_units, context=None):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create(
user = cls.res_users_model.create(
{
"name": "Test User",
"login": login,
Expand All @@ -51,13 +53,14 @@ def _create_user(self, login, groups, company, operating_units, context=None):
)
return user

def _create_crm_team(self, uid, operating_unit):
@classmethod
def _create_crm_team(cls, uid, operating_unit):
"""Create a Sales Team."""
crm = self.crm_team_model.with_user(uid).create(
crm = cls.crm_team_model.with_user(uid).create(
{
"name": "CRM team",
"operating_unit_id": operating_unit.id,
"company_id": self.company.id,
"company_id": cls.company.id,
}
)
return crm
Expand Down
5 changes: 2 additions & 3 deletions sales_team_operating_unit/views/crm_team_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
<field name="model">crm.team</field>
<field name="inherit_id" ref="sales_team.crm_team_view_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="currency_id" position="before">
<field
name="operating_unit_id"
groups="operating_unit.group_multi_operating_unit"
domain="[('company_id','=', company_id),
('user_ids', 'in', uid)]"
domain="[('user_ids', 'in', uid)]"
options="{'no_create': True}"
/>
</field>
Expand Down

0 comments on commit f2491fe

Please sign in to comment.