-
-
Notifications
You must be signed in to change notification settings - Fork 235
/
test_crm_team_operating_unit.py
77 lines (71 loc) · 3.36 KB
/
test_crm_team_operating_unit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2017-TODAY Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.tests import common
from odoo import exceptions
class TestSaleTeamOperatingUnit(common.TransactionCase):
def setUp(self):
super(TestSaleTeamOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.crm_team_model = self.env['crm.team']
# Groups
self.grp_sale_mngr = self.env.ref('sales_team.group_sale_manager')
self.grp_user = self.env.ref('base.group_user')
# Company
self.company = self.env.ref('base.main_company')
# Main Operating Unit
self.ou1 = self.env.ref('operating_unit.main_operating_unit')
# B2C Operating Unit
self.b2c = self.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])
# Create User 2 with B2C OU
self.user2 = self._create_user('user_2', [self.grp_sale_mngr,
self.grp_user], self.company,
[self.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)
def _create_user(self, login, groups, company, operating_units,
context=None):
""" Create a user. """
group_ids = [group.id for group in groups]
user = self.res_users_model.create({
'name': 'Test User',
'login': login,
'password': 'demo',
'email': 'test@yourcompany.com',
'company_id': company.id,
'company_ids': [(4, company.id)],
'operating_unit_ids': [(4, ou.id) for ou in operating_units],
'groups_id': [(6, 0, group_ids)]
})
return user
def _create_crm_team(self, uid, operating_unit):
"""Create a Sales Team."""
crm = self.crm_team_model.sudo(uid).create({'name': 'CRM team',
'operating_unit_id':
operating_unit.id})
return crm
def test_crm_team(self):
# User 2 is only assigned to B2C Operating Unit, and cannot
# access CRM teams for Main Operating Unit.
team = self.crm_team_model.sudo(self.user2.id).\
search([('id', '=', self.team1.id),
('operating_unit_id', '=', self.ou1.id)])
self.assertEqual(team.ids, [], 'User 2 should not have access to '
'%s' % self.ou1.name)
def test_member_operating_unit(self):
# User 2 is assigned to B2C Operating Unit and cannot be a member of
# a team with the Operating Unit OU1
with self.assertRaises(exceptions.ValidationError):
self.crm_team_model.sudo().create({
'name': 'Test Team',
'operating_unit_id': self.ou1.id,
'member_ids': [(4, self.user2.id)]
})