book: asset-query ausgelagert

This commit is contained in:
Frederik Jaeckel 2023-01-24 21:25:29 +01:00
parent 8232f8042d
commit 8156d521de

31
book.py
View file

@ -152,8 +152,8 @@ class Book(SymbolMixin, metaclass=PoolMeta):
return 4
@classmethod
def get_asset_quantity(cls, cashbooks, names):
""" get quantities
def get_asset_quantity_sql(cls):
""" get table of asset and its value, rate, ...
"""
pool = Pool()
CBook = pool.get('cashbook.book')
@ -161,7 +161,6 @@ class Book(SymbolMixin, metaclass=PoolMeta):
Line = pool.get('cashbook.line')
Asset = pool.get('investment.asset')
Currency = pool.get('currency.currency')
Uom = pool.get('product.uom')
tab_book = CBook.__table__()
tab_type = BookType.__table__()
tab_line = Line.__table__()
@ -169,13 +168,9 @@ class Book(SymbolMixin, metaclass=PoolMeta):
tab_asset = Asset.__table__()
(tab_rate, tab2) = Asset.get_rate_data_sql()
(tab_balance, tab2) = CBook.get_balance_of_cashbook_sql()
cursor = Transaction().connection.cursor()
context = Transaction().context
result = {x:{y.id: None for y in cashbooks} for x in names}
query_date = context.get('qdate', CurrentDate())
company_currency = CBook.default_currency()
query = tab_book.join(tab_line,
condition=(tab_book.id==tab_line.cashbook),
).join(tab_type,
@ -209,9 +204,27 @@ class Book(SymbolMixin, metaclass=PoolMeta):
tab_book.currency, tab_cur.digits, tab_asset.uom,
tab_book.quantity_uom, tab_asset.currency,
tab_balance.balance],
where=tab_book.id.in_([x.id for x in cashbooks]) & \
(tab_type.feature == 'asset'),
where=(tab_type.feature == 'asset'),
)
return (query, tab_book)
@classmethod
def get_asset_quantity(cls, cashbooks, names):
""" get quantities
"""
pool = Pool()
CBook = pool.get('cashbook.book')
Uom = pool.get('product.uom')
Currency = pool.get('currency.currency')
cursor = Transaction().connection.cursor()
context = Transaction().context
(query, tab_book) = cls.get_asset_quantity_sql()
result = {x:{y.id: None for y in cashbooks} for x in names}
company_currency = CBook.default_currency()
query.where &= tab_book.id.in_([x.id for x in cashbooks]) & \
(tab_book.btype != None)
cursor.execute(*query)
records = cursor.fetchall()