line: add performance values to line-form

This commit is contained in:
Frederik Jaeckel 2023-01-29 23:16:22 +01:00
parent 3243fbf844
commit 9edd2d4a95
5 changed files with 132 additions and 0 deletions

59
line.py
View file

@ -85,6 +85,29 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
string='has quantity', readonly=True, states={'invisible': True}),
'on_change_with_splitline_has_quantity')
# performance
current_value = fields.Function(fields.Numeric(string='Value',
help='Valuation of the investment based on the current stock market price.',
readonly=True, digits=(16, Eval('currency_digits', 2)),
states={
'invisible': Eval('feature', '') != 'asset',
}, depends=['currency_digits', 'feature']),
'on_change_with_current_value')
diff_amount = fields.Function(fields.Numeric(string='Difference',
help='Difference between acquisition value and current value',
readonly=True, digits=(16, Eval('currency_digits', 2)),
states={
'invisible': Eval('feature', '') != 'asset',
}, depends=['currency_digits', 'feature']),
'on_change_with_diff_amount')
diff_percent = fields.Function(fields.Numeric(string='Percent',
help='percentage performance since acquisition',
readonly=True, digits=(16, Eval('currency_digits', 2)),
states = {
'invisible': Eval('feature', '') != 'asset',
}, depends=['currency_digits', 'feature']),
'on_change_with_diff_percent')
def get_rec_name(self, name):
""" add quantities - if its a asset-cashbook
"""
@ -212,6 +235,42 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
if cnt1 > 0:
self.quantity = quantity
@fields.depends('quantity', 'cashbook', '_parent_cashbook.current_rate', 'currency_digits')
def on_change_with_current_value(self, name=None):
""" get current value of line by current stock marked price
and quantity
"""
if self.cashbook:
if (self.quantity is not None) and \
(self.cashbook.current_rate is not None):
return (
self.quantity * self.cashbook.current_rate
).quantize(Decimal(str(1/10**self.currency_digits)))
@fields.depends('quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate', 'currency_digits')
def on_change_with_diff_amount(self, name=None):
""" get delta between buy and current value
"""
if self.cashbook:
if (self.quantity is not None) and \
(self.amount is not None) and \
(self.cashbook.current_rate is not None):
return (
self.quantity * self.cashbook.current_rate - self.amount
).quantize(Decimal(str(1/10**self.currency_digits)))
@fields.depends('quantity', 'amount', 'cashbook', '_parent_cashbook.current_rate')
def on_change_with_diff_percent(self, name=None):
""" get performane percent
"""
if self.cashbook:
if (self.quantity is not None) and \
(self.amount is not None) and (self.amount != Decimal('0.0')) and \
(self.cashbook.current_rate is not None):
return (self.quantity * self.cashbook.current_rate * \
Decimal('100.0') / self.amount - Decimal('100.0')
).quantize(Decimal(str(1/10**self.currency_digits)))
@fields.depends('splitlines')
def on_change_with_splitline_has_quantity(self, name=None):
""" get True if splitlines are linked to asset-cashbooks