diff --git a/__init__.py b/__init__.py index a11da2c..b4c75e7 100644 --- a/__init__.py +++ b/__init__.py @@ -10,10 +10,12 @@ from .reconciliation import Reconciliation from .line import Line from .splitline import SplitLine from .assetsetting import AssetSetting +from .asset import AssetRate def register(): Pool.register( + AssetRate, Type, Book, Line, diff --git a/asset.py b/asset.py new file mode 100644 index 0000000..9505d2f --- /dev/null +++ b/asset.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds.de for Tryton. +# The COPYRIGHT file at the top level of this repository contains the +# full copyright notices and license terms. + +from trytond.pool import Pool, PoolMeta +CACHEKEY_ASSETRATE = 'assetrate-%s' + + +class AssetRate(metaclass=PoolMeta): + __name__ = 'investment.rate' + + @classmethod + def create(cls, vlist): + """ update cache-value + """ + MemCache = Pool().get('cashbook.memcache') + + records = super(AssetRate, cls).create(vlist) + for rate in records: + MemCache.record_update(CACHEKEY_ASSETRATE % rate.asset.id, rate) + return records + + @classmethod + def write(cls, *args): + """ update cache-value + """ + MemCache = Pool().get('cashbook.memcache') + + super(AssetRate, cls).write(*args) + + actions = iter(args) + for rates, values in zip(actions, actions): + for rate in rates: + MemCache.record_update(CACHEKEY_ASSETRATE % rate.asset.id, rate) + + @classmethod + def delete(cls, records): + """ set cache to None + """ + MemCache = Pool().get('cashbook.memcache') + + for record in records: + MemCache.record_update(CACHEKEY_ASSETRATE % record.asset.id, None) + super(AssetRate, cls).delete(records) + +# end + diff --git a/book.py b/book.py index c88563a..949c331 100644 --- a/book.py +++ b/book.py @@ -16,6 +16,7 @@ from sql.functions import CurrentDate from sql.aggregate import Sum from sql.conditionals import Case, Coalesce from trytond.modules.cashbook.model import CACHEKEY_CURRENCY +from .asset import CACHEKEY_ASSETRATE class Book(SymbolMixin, metaclass=PoolMeta): @@ -288,6 +289,7 @@ class Book(SymbolMixin, metaclass=PoolMeta): }, { 'model': 'investment.rate', 'query': [('asset.id', '=', x.asset.id)], + 'cachekey': CACHEKEY_ASSETRATE % x.asset.id, } if x.asset is not None else {}], addkeys = [query_date.isoformat()]) for x in cashbooks @@ -426,6 +428,7 @@ class Book(SymbolMixin, metaclass=PoolMeta): }, { 'model': 'investment.rate', 'query': [('asset.id', '=', x.asset.id)], + 'cachekey': CACHEKEY_ASSETRATE % x.asset.id, } if x.asset is not None else {}], addkeys=[ str(company_currency),