Add employee to rule context

issue8825
review252621002
This commit is contained in:
Cédric Krier committed 2019-12-07 15:15:31 +01:00
1 parent cfe1869c71
commit 9818599bba
2 files changed
+24 -1

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add employee to rule context
* Add company and employee administrator group
* Add top level menu entry
+23 -1
View File
@@ -5,7 +5,8 @@ try:
except ImportError:
pytz = None
from trytond.model import ModelSQL, ModelView, fields, dualmethod
from trytond.model import (
ModelSQL, ModelView, fields, dualmethod, EvalEnvironment)
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
@@ -51,6 +52,11 @@ class Date(metaclass=PoolMeta):
class Rule(metaclass=PoolMeta):
__name__ = 'ir.rule'
@classmethod
def __setup__(cls):
super().__setup__()
cls.domain.help += '\n- "employee" from the current user'
@classmethod
def _get_cache_key(cls):
key = super(Rule, cls)._get_cache_key()
@@ -59,6 +65,22 @@ class Rule(metaclass=PoolMeta):
return key + (Transaction().context.get('company'),
Transaction().context.get('employee'))
@classmethod
def _get_context(cls):
pool = Pool()
User = pool.get('res.user')
Employee = pool.get('company.employee')
context = super()._get_context()
# Use root to avoid infinite loop when accessing user attributes
with Transaction().set_user(0):
user = User(Transaction().user)
if user.employee:
with Transaction().set_context(
_check_access=False, _datetime=None):
context['employee'] = EvalEnvironment(
Employee(user.employee.id), Employee)
return context
class Cron(metaclass=PoolMeta):
__name__ = "ir.cron"