From 9e44d3a11f6320251d3c362fdf9309d1d27c4efa Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Sat, 24 Dec 2022 13:14:51 +0100 Subject: [PATCH] book: Feld 'aktueller Kurs' --- book.py | 24 ++++++++++++++++++++++-- locale/de.po | 8 ++++++++ locale/en.po | 28 ++++++++++++++++++++++++++-- tests/test_book.py | 2 ++ view/book_form.xml | 2 ++ 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/book.py b/book.py index 14ac53d..c81afb7 100644 --- a/book.py +++ b/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: diff --git a/locale/de.po b/locale/de.po index 6b49abe..1ba5d0e 100644 --- a/locale/de.po +++ b/locale/de.po @@ -98,6 +98,14 @@ msgctxt "help:cashbook.book,diff_percent:" msgid "percentage performance since acquisition" msgstr "prozentuale Wertentwicklung seit Anschaffung" +msgctxt "field:cashbook.book,current_rate:" +msgid "Rate" +msgstr "Kurs" + +msgctxt "help:cashbook.book,current_rate:" +msgid "Rate per unit of investment based on current stock exchange price." +msgstr "Kurs pro Einheit der Investition anhand des aktuellen Börsenkurses." + ################# # cashbook.line # diff --git a/locale/en.po b/locale/en.po index b9f47a1..c54ba44 100644 --- a/locale/en.po +++ b/locale/en.po @@ -15,8 +15,8 @@ msgid "Quantity" msgstr "Quantity" msgctxt "view:cashbook.book:" -msgid "Current value of the asset" -msgstr "Current value of the asset" +msgid "Current valuation of the investment" +msgstr "Current valuation of the investment" msgctxt "field:cashbook.book,asset:" msgid "Asset" @@ -74,6 +74,30 @@ msgctxt "help:cashbook.book,current_value_ref:" msgid "Valuation of the investment based on the current stock exchange price, converted into the company currency." msgstr "Valuation of the investment based on the current stock exchange price, converted into the company currency." +msgctxt "field:cashbook.book,diff_amount:" +msgid "Difference" +msgstr "Difference" + +msgctxt "help:cashbook.book,diff_amount:" +msgid "Difference between acquisition value and current value" +msgstr "Difference between acquisition value and current value" + +msgctxt "field:cashbook.book,diff_percent:" +msgid "Percent" +msgstr "Percent" + +msgctxt "help:cashbook.book,diff_percent:" +msgid "percentage performance since acquisition" +msgstr "percentage performance since acquisition" + +msgctxt "field:cashbook.book,current_rate:" +msgid "Rate" +msgstr "Rate" + +msgctxt "help:cashbook.book,current_rate:" +msgid "Rate per unit of investment based on current stock exchange price." +msgstr "Rate per unit of investment based on current stock exchange price." + msgctxt "field:cashbook.line,quantity_digits:" msgid "Digits" msgstr "Digits" diff --git a/tests/test_book.py b/tests/test_book.py index fb55abb..c2bc50b 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -264,6 +264,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.current_value_ref, Decimal('1175.80')) self.assertEqual(book2.diff_amount, Decimal('-74.20')) self.assertEqual(book2.diff_percent, Decimal('-5.94')) + self.assertEqual(book2.current_rate, Decimal('58.79')) @with_transaction() def test_assetbook_check_uom_and_currency_convert2(self): @@ -378,6 +379,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.current_value_ref, Decimal('1175.80')) # EUR self.assertEqual(book2.diff_amount, Decimal('-132.99')) self.assertEqual(book2.diff_percent, Decimal('-10.64')) + self.assertEqual(book2.current_rate, Decimal('55.85')) @with_transaction() def test_assetbook_book_uom(self): diff --git a/view/book_form.xml b/view/book_form.xml index 6d1115e..22f21ed 100644 --- a/view/book_form.xml +++ b/view/book_form.xml @@ -25,6 +25,8 @@ full copyright notices and license terms. -->