Add a new rule in user company employee model

#035369
This commit is contained in:
Raimon Esteve 2018-09-13 12:36:30 +02:00
parent 189f30ccef
commit 294b9e5664
2 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, If
__all__ = ['Employee']
@ -15,3 +15,15 @@ class Employee(metaclass=PoolMeta):
('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)

View File

@ -13,5 +13,16 @@ this repository contains the full copyright notices and license terms. -->
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>