Remove employee rule to allow user and user preferences change employee
#035369
This commit is contained in:
parent
294b9e5664
commit
90fc474338
17
employee.py
17
employee.py
|
@ -1,7 +1,8 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Employee']
|
||||
|
||||
|
@ -17,13 +18,7 @@ class Employee(metaclass=PoolMeta):
|
|||
]
|
||||
|
||||
@classmethod
|
||||
def search(cls, args, offset=0, limit=None, order=None, count=False,
|
||||
query=False):
|
||||
Rule = Pool().get('ir.rule')
|
||||
# TODO clear domain cache because when an user change company (set preferences),
|
||||
# the new domain cache is [u'company', u'=', None] and not return
|
||||
# employees with company context. At the moment, search employees
|
||||
# drop domain cache (clear)
|
||||
Rule._domain_get_cache.clear()
|
||||
return super(Employee, cls).search(args, offset, limit, order,
|
||||
count, query)
|
||||
def read(cls, ids, fields_names=None):
|
||||
# Skip access rule
|
||||
with Transaction().set_user(0):
|
||||
return super(Employee, cls).read(ids, fields_names=fields_names)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval, If
|
||||
|
||||
__all__ = ['Employee', 'UserEmployee']
|
||||
|
||||
|
||||
class Employee:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'company.employee'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Employee, cls).__setup__()
|
||||
cls.company.domain = [
|
||||
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1)),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def search(cls, args, offset=0, limit=None, order=None, count=False,
|
||||
query=False):
|
||||
Rule = Pool().get('ir.rule')
|
||||
# TODO clear domain cache because when an user change company (set preferences),
|
||||
# the new domain cache is [u'company', u'=', None] and not return
|
||||
# employees with company context. At the moment, search employees
|
||||
# drop domain cache (clear)
|
||||
Rule._domain_get_cache.clear()
|
||||
return super(Employee, cls).search(args, offset, limit, order,
|
||||
count, query)
|
||||
|
||||
|
||||
class UserEmployee:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'res.user-company.employee'
|
||||
company = fields.Function(fields.Many2One('company.company',
|
||||
'Company'), 'get_company', searcher='search_company')
|
||||
|
||||
def get_company(self, name):
|
||||
return employee.id if self.employee else None
|
||||
|
||||
@classmethod
|
||||
def search_company(cls, name, clause):
|
||||
return [('employee.%s' % name,) + tuple(clause[1:])]
|
20
employee.xml
20
employee.xml
|
@ -3,26 +3,10 @@
|
|||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.rule.group" id="rule_group_employee">
|
||||
<field name="model" search="[('model', '=', 'company.employee')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_employee1">
|
||||
<record model="ir.action.act_window" id="company.act_employee_form">
|
||||
<field name="domain"
|
||||
eval="[('company', '=', Eval('user', {}).get('company', None))]"
|
||||
eval="[('company', '=', Eval('context', {}).get('company', -1))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_employee"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_user_company_employee">
|
||||
<field name="model" search="[('model', '=', 'res.user-company.employee')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_group_user_company_employee1">
|
||||
<field name="domain"
|
||||
eval="[('employee.company', '=', Eval('user', {}).get('company', None))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_user_company_employee"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in New Issue