Use 'irrulecontext' to add 'user_id' to context of ir.rule
This commit is contained in:
parent
6aca58bcc2
commit
08d8121f57
3 changed files with 9 additions and 19 deletions
25
ir.py
25
ir.py
|
@ -3,7 +3,6 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
|
@ -14,22 +13,12 @@ class Rule(metaclass=PoolMeta):
|
|||
def _context_modelnames(cls):
|
||||
""" list of models to add 'user_id' to context
|
||||
"""
|
||||
return [
|
||||
'cashbook.book', 'cashbook.line', 'cashbook.recon',
|
||||
'cashbook.split']
|
||||
|
||||
@classmethod
|
||||
def _get_context(cls, model_name):
|
||||
context = super()._get_context(model_name)
|
||||
if model_name in cls._context_modelnames():
|
||||
context['user_id'] = Transaction().user
|
||||
return context
|
||||
|
||||
@classmethod
|
||||
def _get_cache_key(cls, model_name):
|
||||
key = super()._get_cache_key(model_name)
|
||||
if model_name in cls._context_modelnames():
|
||||
key = (*key, Transaction().user)
|
||||
return key
|
||||
result = super(Rule, cls)._context_modelnames()
|
||||
return result | {
|
||||
'cashbook.book',
|
||||
'cashbook.line',
|
||||
'cashbook.recon',
|
||||
'cashbook.split'
|
||||
}
|
||||
|
||||
# end Rule
|
||||
|
|
|
@ -5,6 +5,7 @@ depends:
|
|||
currency
|
||||
party
|
||||
company
|
||||
irrulecontext
|
||||
xml:
|
||||
icon.xml
|
||||
group.xml
|
||||
|
|
|
@ -1 +1 @@
|
|||
|
||||
irrulecontext;7.0.1;7.0.999;mds
|
||||
|
|
Loading…
Reference in a new issue