book:caching for line, settings: cache clear

This commit is contained in:
Frederik Jaeckel 2023-02-27 20:46:41 +01:00
parent 02bde17f6b
commit 17a4499ac7
2 changed files with 13 additions and 1 deletions

View file

@ -21,4 +21,13 @@ class AssetSetting(ModelSingleton, ModelSQL, ModelView):
model_name='cashbook.book', ondelete='RESTRICT', model_name='cashbook.book', ondelete='RESTRICT',
help='Profit and loss on sale of assets are recorded in the cash book.') help='Profit and loss on sale of assets are recorded in the cash book.')
@classmethod
def write(cls, *args):
""" clear cache-values
"""
MemCache = Pool().get('cashbook.memcache')
MemCache._cashbook_value_cache.clear_all()
super(AssetSetting, cls).write(*args)
# end AssetSetting # end AssetSetting

View file

@ -15,7 +15,7 @@ from sql import Literal
from sql.functions import CurrentDate from sql.functions import CurrentDate
from sql.aggregate import Sum from sql.aggregate import Sum
from sql.conditionals import Case, Coalesce from sql.conditionals import Case, Coalesce
from trytond.modules.cashbook.model import CACHEKEY_CURRENCY from trytond.modules.cashbook.model import CACHEKEY_CURRENCY, CACHEKEY_CASHBOOK
from .asset import CACHEKEY_ASSETRATE from .asset import CACHEKEY_ASSETRATE
@ -282,6 +282,7 @@ class Book(SymbolMixin, metaclass=PoolMeta):
query = [{ query = [{
'model': 'cashbook.line', 'model': 'cashbook.line',
'query': [('cashbook.parent', 'child_of', [x.id])], 'query': [('cashbook.parent', 'child_of', [x.id])],
'cachekey': CACHEKEY_CASHBOOK % x.id,
}, { }, {
'model': 'currency.currency.rate', 'model': 'currency.currency.rate',
'query': [('currency.id', '=', x.currency.id)], 'query': [('currency.id', '=', x.currency.id)],
@ -422,9 +423,11 @@ class Book(SymbolMixin, metaclass=PoolMeta):
query = [{ query = [{
'model': 'cashbook.line', 'model': 'cashbook.line',
'query': [('cashbook.parent', 'child_of', [x.id])], 'query': [('cashbook.parent', 'child_of', [x.id])],
'cachekey': CACHEKEY_CASHBOOK % x.id,
}, { }, {
'model': 'currency.currency.rate', 'model': 'currency.currency.rate',
'query': [('currency.id', '=', x.currency.id)], 'query': [('currency.id', '=', x.currency.id)],
'cachekey': CACHEKEY_CURRENCY % x.currency.id,
}, { }, {
'model': 'investment.rate', 'model': 'investment.rate',
'query': [('asset.id', '=', x.asset.id)], 'query': [('asset.id', '=', x.asset.id)],