book: Feld 'aktueller Kurs'
This commit is contained in:
parent
026d72823d
commit
9e44d3a11f
5 changed files with 60 additions and 4 deletions
24
book.py
24
book.py
|
@ -95,11 +95,21 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
diff_amount = fields.Function(fields.Numeric(string='Difference',
|
||||
help='Difference between acquisition value and current value',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
depends=['currency_digits']), 'get_asset_quantity')
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']), 'get_asset_quantity')
|
||||
diff_percent = fields.Function(fields.Numeric(string='Percent',
|
||||
help='percentage performance since acquisition',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
depends=['currency_digits']), 'get_asset_quantity')
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']), 'get_asset_quantity')
|
||||
current_rate = fields.Function(fields.Numeric(string='Rate',
|
||||
help='Rate per unit of investment based on current stock exchange price.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']), 'get_asset_quantity')
|
||||
|
||||
@classmethod
|
||||
def view_attributes(cls):
|
||||
|
@ -131,11 +141,13 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
"""
|
||||
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__()
|
||||
tab_cur = Currency.__table__()
|
||||
tab_asset = Asset.__table__()
|
||||
|
@ -150,6 +162,8 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
|
||||
query = tab_book.join(tab_line,
|
||||
condition=(tab_book.id==tab_line.cashbook),
|
||||
).join(tab_type,
|
||||
condition=tab_book.btype==tab_type.id,
|
||||
).join(tab_cur,
|
||||
condition=tab_book.currency==tab_cur.id,
|
||||
).join(tab_asset,
|
||||
|
@ -178,6 +192,8 @@ 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'),
|
||||
)
|
||||
cursor.execute(*query)
|
||||
records = cursor.fetchall()
|
||||
|
@ -212,6 +228,10 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
record[9] - Decimal('100.0')
|
||||
).quantize(Decimal(str(1/10**record[5]))) \
|
||||
if record[9] != Decimal('0.0') else None,
|
||||
'current_rate': (
|
||||
current_value / record[1]
|
||||
).quantize(Decimal(str(1/10**record[5]))) \
|
||||
if record[1] != Decimal('0.0') else None,
|
||||
}
|
||||
|
||||
for name in names:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue