book: asset-query ausgelagert
This commit is contained in:
parent
8232f8042d
commit
8156d521de
1 changed files with 23 additions and 10 deletions
33
book.py
33
book.py
|
@ -152,16 +152,15 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_asset_quantity(cls, cashbooks, names):
|
def get_asset_quantity_sql(cls):
|
||||||
""" get quantities
|
""" get table of asset and its value, rate, ...
|
||||||
"""
|
"""
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
CBook = pool.get('cashbook.book')
|
CBook = pool.get('cashbook.book')
|
||||||
BookType = pool.get('cashbook.type')
|
BookType = pool.get('cashbook.type')
|
||||||
Line = pool.get('cashbook.line')
|
Line = pool.get('cashbook.line')
|
||||||
Asset = pool.get('investment.asset')
|
Asset = pool.get('investment.asset')
|
||||||
Currency = pool.get('currency.currency')
|
Currency = pool.get('currency.currency')
|
||||||
Uom = pool.get('product.uom')
|
|
||||||
tab_book = CBook.__table__()
|
tab_book = CBook.__table__()
|
||||||
tab_type = BookType.__table__()
|
tab_type = BookType.__table__()
|
||||||
tab_line = Line.__table__()
|
tab_line = Line.__table__()
|
||||||
|
@ -169,13 +168,9 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
||||||
tab_asset = Asset.__table__()
|
tab_asset = Asset.__table__()
|
||||||
(tab_rate, tab2) = Asset.get_rate_data_sql()
|
(tab_rate, tab2) = Asset.get_rate_data_sql()
|
||||||
(tab_balance, tab2) = CBook.get_balance_of_cashbook_sql()
|
(tab_balance, tab2) = CBook.get_balance_of_cashbook_sql()
|
||||||
cursor = Transaction().connection.cursor()
|
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
|
|
||||||
result = {x:{y.id: None for y in cashbooks} for x in names}
|
|
||||||
query_date = context.get('qdate', CurrentDate())
|
query_date = context.get('qdate', CurrentDate())
|
||||||
company_currency = CBook.default_currency()
|
|
||||||
|
|
||||||
query = tab_book.join(tab_line,
|
query = tab_book.join(tab_line,
|
||||||
condition=(tab_book.id==tab_line.cashbook),
|
condition=(tab_book.id==tab_line.cashbook),
|
||||||
).join(tab_type,
|
).join(tab_type,
|
||||||
|
@ -209,9 +204,27 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
||||||
tab_book.currency, tab_cur.digits, tab_asset.uom,
|
tab_book.currency, tab_cur.digits, tab_asset.uom,
|
||||||
tab_book.quantity_uom, tab_asset.currency,
|
tab_book.quantity_uom, tab_asset.currency,
|
||||||
tab_balance.balance],
|
tab_balance.balance],
|
||||||
where=tab_book.id.in_([x.id for x in cashbooks]) & \
|
where=(tab_type.feature == 'asset'),
|
||||||
(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)
|
cursor.execute(*query)
|
||||||
records = cursor.fetchall()
|
records = cursor.fetchall()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue