-
Notifications
You must be signed in to change notification settings - Fork 20
/
company.py
63 lines (48 loc) · 1.57 KB
/
company.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
# -*- coding: utf-8 -*-
"""
company
:copyright: (c) 2012-2014 by Openlabs Technologies & Consulting (P) Limited
:license: GPLv3, see LICENSE for more details.
"""
from trytond.pool import PoolMeta, Pool
from trytond.model import ModelSQL, fields
__all__ = ['Company', 'CompanyProjectAdmins']
__metaclass__ = PoolMeta
class Company:
"""
Add project admins to company
"""
__name__ = "company.company"
project_admins = fields.Function(
fields.One2Many("nereid.user", None, "Project Admins"),
'get_admins'
)
project_managers = fields.Function(
fields.One2Many("nereid.user", None, "Project Managers"),
'get_admins'
)
def get_admins(self, name):
"""
Returns all the nereid users who are admin for this company
"""
NereidUser = Pool().get('nereid.user')
assert name in ('project_admins', 'project_managers')
if name == 'project_admins':
permission = 'project.admin'
else:
permission = 'project.manager'
domain = [
('company', '=', self.id),
('permissions.value', '=', permission),
]
return map(int, NereidUser.search(domain))
class CompanyProjectAdmins(ModelSQL):
"Company Admins"
__name__ = 'company.company-nereid.user'
_table = 'company_company_nereid_user_rel'
company = fields.Many2One(
'company.company', 'Company',
ondelete='CASCADE', select=1, required=True)
user = fields.Many2One(
'nereid.user', 'User', select=1, required=True
)