add update of cashbooks on update of asset-rates
This commit is contained in:
parent
4f87242548
commit
9b0a3691a4
3 changed files with 401 additions and 4 deletions
38
asset.py
38
asset.py
|
@ -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 AssetRate(metaclass=PoolMeta):
|
||||
|
@ -13,22 +13,52 @@ class AssetRate(metaclass=PoolMeta):
|
|||
def create(cls, vlist):
|
||||
""" update cache-value
|
||||
"""
|
||||
pool = Pool()
|
||||
Cashbook = pool.get('cashbook.book')
|
||||
ValueStore = pool.get('cashbook.values')
|
||||
|
||||
records = super(AssetRate, cls).create(vlist)
|
||||
# TODO: update cashbooks using this asset
|
||||
|
||||
ValueStore.update_books(
|
||||
ValueStore.get_book_by_books(
|
||||
Cashbook.search([
|
||||
('asset', 'in', [
|
||||
x.asset.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(AssetRate, cls).write(*args)
|
||||
# TODO: update cashbooks using this asset
|
||||
|
||||
ValueStore.update_books(
|
||||
ValueStore.get_book_by_books(
|
||||
Cashbook.search([
|
||||
('asset', 'in', [
|
||||
x.asset.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([
|
||||
('asset', 'in', [x.asset.id for x in records])]))
|
||||
|
||||
super(AssetRate, cls).delete(records)
|
||||
# TODO: update cashbooks using this asset
|
||||
ValueStore.update_books(books)
|
||||
|
||||
# end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue