add worker-based precalculation of cashbook-values

This commit is contained in:
Frederik Jaeckel 2023-12-27 15:49:02 +01:00
parent 9ef465f40f
commit 5d8f924960
17 changed files with 1060 additions and 98 deletions

View file

@ -3,7 +3,7 @@
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.pool import PoolMeta
from trytond.pool import PoolMeta, Pool
class CurrencyRate(metaclass=PoolMeta):
@ -13,22 +13,51 @@ class CurrencyRate(metaclass=PoolMeta):
def create(cls, vlist):
""" update cache-value
"""
pool = Pool()
Cashbook = pool.get('cashbook.book')
ValueStore = pool.get('cashbook.values')
records = super(CurrencyRate, cls).create(vlist)
# TODO: update cashbooks using this rate
ValueStore.update_books(
ValueStore.get_book_by_books(
Cashbook.search([
('currency', 'in', [
x.currency.id for x in records])])))
return records
@classmethod
def write(cls, *args):
""" update cache-value
"""
pool = Pool()
Cashbook = pool.get('cashbook.book')
ValueStore = pool.get('cashbook.values')
actions = iter(args)
all_rates = []
for rates, values in zip(actions, actions):
all_rates.extend(rates)
super(CurrencyRate, cls).write(*args)
# TODO: update cashbooks using this rate
ValueStore.update_books(
ValueStore.get_book_by_books(
Cashbook.search([
('currency', 'in', [
x.currency.id for x in all_rates])])))
@classmethod
def delete(cls, records):
""" set cache to None
"""
pool = Pool()
Cashbook = pool.get('cashbook.book')
ValueStore = pool.get('cashbook.values')
books = ValueStore.get_book_by_books(Cashbook.search([
('currency', 'in', [x.currency.id for x in records])]))
super(CurrencyRate, cls).delete(records)
# TODO: update cashbooks using this rate
ValueStore.update_books(books)
# end