diff --git a/line.py b/line.py
index c35946a..adfc1bd 100644
--- a/line.py
+++ b/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
diff --git a/locale/de.po b/locale/de.po
index 9017a1d..cc86f22 100644
--- a/locale/de.po
+++ b/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 #
diff --git a/locale/en.po b/locale/en.po
index 1cc9a42..ce29b4e 100644
--- a/locale/en.po
+++ b/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"
diff --git a/tests/test_book.py b/tests/test_book.py
index d3dc2c3..08e8f80 100644
--- a/tests/test_book.py
+++ b/tests/test_book.py
@@ -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'))
diff --git a/view/line_form.xml b/view/line_form.xml
index 35e5369..6ecafb8 100644
--- a/view/line_form.xml
+++ b/view/line_form.xml
@@ -23,4 +23,18 @@ full copyright notices and license terms. -->
+
+
+
+
+
+
+
+
+
+
+
+
+
+