forked from openlabs/nereid-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
company.py
71 lines (53 loc) · 1.79 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
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
company
Add the employee relation ship to nereid user
:copyright: (c) 2012 by Openlabs Technologies & Consulting (P) Limited
:license: GPLv3, see LICENSE for more details.
"""
from nereid import request
from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Eval, Get
class Company(ModelSQL, ModelView):
"""
Add project admins to company
"""
_name = "company.company"
#: Administrators for project management. Only admins can create new
project_admins = fields.Many2Many(
'company.company-nereid.user', 'company', 'user',
'Project Administrators'
)
Company()
class CompanyProjectAdmins(ModelSQL):
_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
)
CompanyProjectAdmins()
class NereidUser(ModelSQL, ModelView):
"""
Add employee
"""
_name = "nereid.user"
#: Allow the nereid user to be connected to an internal employee. This
#: indicates that the user is an employee and not a regular participant
employee = fields.Many2One('company.employee', 'Employee',
select=True, domain=[
('company', '=', Get(Eval('context', {}), 'company')),
('party', '=', Eval('party'))
])
def is_project_admin(self, user):
"""
Returns True if the user is in the website admins list
:param user: Browse record of the user
:return: True
"""
if user in request.nereid_website.company.project_admins:
return True
return False
NereidUser()