From 8156d521ded654a673f2d456689c49c30cf1c627 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Tue, 24 Jan 2023 21:25:29 +0100 Subject: [PATCH] book: asset-query ausgelagert --- book.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/book.py b/book.py index 332d514..2858b37 100644 --- a/book.py +++ b/book.py @@ -152,16 +152,15 @@ 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') BookType = pool.get('cashbook.type') 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()