cashbook/currency.py

64 lines
1.8 KiB
Python
Raw Normal View History

2023-02-26 21:49:21 +00:00
# -*- 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 PoolMeta, Pool
2023-02-26 21:49:21 +00:00
class CurrencyRate(metaclass=PoolMeta):
__name__ = 'currency.currency.rate'
@classmethod
def create(cls, vlist):
""" update cache-value
"""
pool = Pool()
Cashbook = pool.get('cashbook.book')
ValueStore = pool.get('cashbook.values')
2023-02-26 21:49:21 +00:00
records = super(CurrencyRate, cls).create(vlist)
ValueStore.update_books(
ValueStore.get_book_by_books(
Cashbook.search([
('currency', 'in', [
x.currency.id for x in records])])))
2023-02-26 21:49:21 +00:00
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)
2023-02-26 21:49:21 +00:00
super(CurrencyRate, cls).write(*args)
ValueStore.update_books(
ValueStore.get_book_by_books(
Cashbook.search([
('currency', 'in', [
x.currency.id for x in all_rates])])))
2023-02-26 21:49:21 +00:00
@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])]))
2023-02-26 21:49:21 +00:00
super(CurrencyRate, cls).delete(records)
ValueStore.update_books(books)
2023-02-26 21:49:21 +00:00
# end