allow extension of context-models

This commit is contained in:
Frederik Jaeckel 2023-12-04 20:06:02 +01:00
parent 7e6d2660ad
commit 72f0325a71

10
ir.py
View file

@ -10,17 +10,23 @@ from trytond.pool import PoolMeta
class Rule(metaclass=PoolMeta):
__name__ = 'ir.rule'
@classmethod
def _context_modelnames(cls):
""" list of models to add 'user_id' to context
"""
return ['cashbook.book', 'cashbook.line', 'cashbook.recon']
@classmethod
def _get_context(cls, model_name):
context = super()._get_context(model_name)
if model_name in {'cashbook.book', 'cashbook.line', 'cashbook.recon'}:
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 {'cashbook.book', 'cashbook.line', 'cashbook.recon'}:
if model_name in cls._context_modelnames():
key = (*key, Transaction().user)
return key