line: add performance values to line-form
This commit is contained in:
parent
9669a8d85b
commit
ea7f114e94
5 changed files with 132 additions and 0 deletions
59
line.py
59
line.py
|
@ -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
|
||||
|
|
28
locale/de.po
28
locale/de.po
|
@ -162,6 +162,10 @@ msgstr "Umrechnungsfaktor zwischen den Einheiten der teilnehmenden Kassenbücher
|
|||
#################
|
||||
# cashbook.line #
|
||||
#################
|
||||
msgctxt "view:cashbook.line:"
|
||||
msgid "Performance"
|
||||
msgstr "Wertentwicklung"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Dezimalstellen"
|
||||
|
@ -218,6 +222,30 @@ msgctxt "field:cashbook.line,splitline_has_quantity:"
|
|||
msgid "has quantity"
|
||||
msgstr "hat Anzahl"
|
||||
|
||||
msgctxt "field:cashbook.line,current_value:"
|
||||
msgid "Value"
|
||||
msgstr "Wert"
|
||||
|
||||
msgctxt "help:cashbook.line,current_value:"
|
||||
msgid "Valuation of the investment based on the current stock market price."
|
||||
msgstr "Bewertung der Vermögensanlage anhand des aktuellen Börsenkurses."
|
||||
|
||||
msgctxt "field:cashbook.line,diff_amount:"
|
||||
msgid "Difference"
|
||||
msgstr "Differenz"
|
||||
|
||||
msgctxt "help:cashbook.line,diff_amount:"
|
||||
msgid "Difference between acquisition value and current value"
|
||||
msgstr "Differenz zwischen Anschaffungswert und aktuellem Wert"
|
||||
|
||||
msgctxt "field:cashbook.line,diff_percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Prozent"
|
||||
|
||||
msgctxt "help:cashbook.line,diff_percent:"
|
||||
msgid "percentage performance since acquisition"
|
||||
msgstr "prozentuale Wertentwicklung seit Anschaffung"
|
||||
|
||||
|
||||
##################
|
||||
# cashbook.recon #
|
||||
|
|
28
locale/en.po
28
locale/en.po
|
@ -146,6 +146,10 @@ msgctxt "help:cashbook.split,factor_2nd_uom:"
|
|||
msgid "Conversion factor between the units of the participating cash books."
|
||||
msgstr "Conversion factor between the units of the participating cash books."
|
||||
|
||||
msgctxt "view:cashbook.line:"
|
||||
msgid "Performance"
|
||||
msgstr "Performance"
|
||||
|
||||
msgctxt "field:cashbook.line,quantity_digits:"
|
||||
msgid "Digits"
|
||||
msgstr "Digits"
|
||||
|
@ -202,6 +206,30 @@ msgctxt "field:cashbook.line,splitline_has_quantity:"
|
|||
msgid "has quantity"
|
||||
msgstr "has quantity"
|
||||
|
||||
msgctxt "field:cashbook.line,current_value:"
|
||||
msgid "Value"
|
||||
msgstr "Value"
|
||||
|
||||
msgctxt "help:cashbook.line,current_value:"
|
||||
msgid "Valuation of the investment based on the current stock market price."
|
||||
msgstr "Valuation of the investment based on the current stock market price."
|
||||
|
||||
msgctxt "field:cashbook.line,diff_amount:"
|
||||
msgid "Difference"
|
||||
msgstr "Difference"
|
||||
|
||||
msgctxt "help:cashbook.line,diff_amount:"
|
||||
msgid "Difference between acquisition value and current value"
|
||||
msgstr "Difference between acquisition value and current value"
|
||||
|
||||
msgctxt "field:cashbook.line,diff_percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Percent"
|
||||
|
||||
msgctxt "help:cashbook.line,diff_percent:"
|
||||
msgid "percentage performance since acquisition"
|
||||
msgstr "percentage performance since acquisition"
|
||||
|
||||
msgctxt "field:cashbook.recon,start_quantity:"
|
||||
msgid "Start Quantity"
|
||||
msgstr "Start Quantity"
|
||||
|
|
|
@ -296,6 +296,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[0].quantity_digits, 3)
|
||||
self.assertEqual(book.lines[0].quantity_uom.symbol, 'u')
|
||||
self.assertEqual(book.lines[0].current_value, Decimal('3.88'))
|
||||
self.assertEqual(book.lines[0].diff_amount, Decimal('1.38'))
|
||||
self.assertEqual(book.lines[0].diff_percent, Decimal('55.18'))
|
||||
|
||||
self.assertEqual(book.lines[1].amount, Decimal('4.0'))
|
||||
self.assertEqual(book.lines[1].quantity, Decimal('3.3'))
|
||||
|
|
|
@ -23,4 +23,18 @@ full copyright notices and license terms. -->
|
|||
<field name="factor_2nd_uom"/>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/notebook/page[@name='description']" position="after">
|
||||
<page name="current_value" col="5" string="Performance">
|
||||
<label name="current_value"/>
|
||||
<field name="current_value" symbol="currency"/>
|
||||
<label name="diff_amount"/>
|
||||
<field name="diff_amount" symbol="currency"/>
|
||||
|
||||
<group id="diff_percent" col="2">
|
||||
<field name="diff_percent" xexpand="0"/>
|
||||
<label name="diff_percent" xalign="0.0" string="%" xexpand="1"/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
</data>
|
||||
|
|
Loading…
Reference in a new issue