From e94a869166887e91dce8117f648f701cac6ddde0 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 30 Dec 2022 23:55:00 +0100 Subject: [PATCH] line: quantity_credit/debit + test book: berechnet 'quantity' aus quantity_credit/debit --- book.py | 5 +- line.py | 69 ++++++++++--- locale/de.po | 8 ++ locale/en.po | 240 +++++++++++++++++++++++---------------------- tests/test_book.py | 16 +++ view/line_form.xml | 5 + 6 files changed, 210 insertions(+), 133 deletions(-) diff --git a/book.py b/book.py index f438d5d..b753742 100644 --- a/book.py +++ b/book.py @@ -180,10 +180,11 @@ class Book(SymbolMixin, metaclass=PoolMeta): ).select( tab_book.id, # 0 Coalesce(Sum(Case( - (tab_line.date <= query_date, tab_line.quantity), + (tab_line.date <= query_date, + tab_line.quantity_credit - tab_line.quantity_debit), else_ = Decimal('0.0'), )), Decimal('0.0')).as_('quantity'), # 1 - Sum(tab_line.quantity).as_('quantity_all'), # 2 + Sum(tab_line.quantity_credit - tab_line.quantity_debit).as_('quantity_all'), # 2 Coalesce(tab_rate.rate, Decimal('0.0')).as_('rate'), # 3 tab_book.currency, # 4 tab_cur.digits.as_('currency_digits'), # 5 diff --git a/line.py b/line.py index d1d0584..b724fd2 100644 --- a/line.py +++ b/line.py @@ -9,27 +9,37 @@ from trytond.pool import PoolMeta from trytond.pyson import Eval, Or, If from trytond.modules.cashbook.line import STATES, DEPENDS +STATESQ = { + 'required': Or( + Eval('feature', '') == 'asset', + Eval('booktransf_feature', '') == 'asset', + ), + 'invisible': ~Or( + Eval('feature', '') == 'asset', + Eval('booktransf_feature', '') == 'asset', + ), + 'readonly': Or( + STATES['readonly'], + Eval('bookingtype', '').in_(['spin', 'spout']), + ), + } +DEPENDSQ = DEPENDS+['feature', 'booktransf_feature', + 'quantity_digits', 'bookingtype'] + class Line(metaclass=PoolMeta): __name__ = 'cashbook.line' quantity = fields.Numeric(string='Quantity', digits=(16, Eval('quantity_digits', 4)), - states={ - 'required': Or( - Eval('feature', '') == 'asset', - Eval('booktransf_feature', '') == 'asset', - ), - 'invisible': ~Or( - Eval('feature', '') == 'asset', - Eval('booktransf_feature', '') == 'asset', - ), - 'readonly': Or( - STATES['readonly'], - Eval('bookingtype', '').in_(['spin', 'spout']), - ), - }, depends=DEPENDS+['feature', 'booktransf_feature', - 'quantity_digits', 'bookingtype']) + states=STATESQ, depends=DEPENDSQ) + quantity_credit = fields.Numeric(string='Quantity Credit', + digits=(16, Eval('quantity_digits', 4)), + states=STATESQ, depends=DEPENDSQ) + quantity_debit = fields.Numeric(string='Quantity Debit', + digits=(16, Eval('quantity_digits', 4)), + states=STATESQ, depends=DEPENDSQ) + quantity_digits = fields.Function(fields.Integer(string='Digits', readonly=True, states={'invisible': True}), 'on_change_with_quantity_digits') @@ -46,6 +56,35 @@ class Line(metaclass=PoolMeta): }, depends=['currency_digits', 'quantity_digits', 'feature']), 'on_change_with_asset_rate') + @classmethod + def get_debit_credit(cls, values): + """ compute quantity_debit/quantity_credit from quantity + """ + values2 = super(Line, cls).get_debit_credit(values) + + if isinstance(values, dict): + type_ = values.get('bookingtype', None) + quantity = values.get('quantity', None) + else : + type_ = getattr(values, 'bookingtype', None) + quantity = getattr(values, 'quantity', None) + + if type_: + if quantity is not None: + if type_ in ['in', 'mvin', 'spin']: + values2.update({ + 'quantity_debit': Decimal('0.0'), + 'quantity_credit': quantity, + }) + elif type_ in ['out', 'mvout', 'spout']: + values2.update({ + 'quantity_debit': quantity, + 'quantity_credit': Decimal('0.0'), + }) + else : + raise ValueError('invalid "bookingtype"') + return values2 + @classmethod def get_counterpart_values(cls, line, values={}): """ add quantity to counterpart diff --git a/locale/de.po b/locale/de.po index 11e068f..4657712 100644 --- a/locale/de.po +++ b/locale/de.po @@ -122,6 +122,14 @@ msgctxt "field:cashbook.line,quantity:" msgid "Quantity" msgstr "Anzahl" +msgctxt "field:cashbook.line,quantity_credit:" +msgid "Quantity Credit" +msgstr "Anzahlgutschrift" + +msgctxt "field:cashbook.line,quantity_debit:" +msgid "Quantity Debit" +msgstr "Anzahllastschrift" + msgctxt "field:cashbook.line,quantity_symbol:" msgid "Symbol" msgstr "Symbol" diff --git a/locale/en.po b/locale/en.po index 870dabd..04c095d 100644 --- a/locale/en.po +++ b/locale/en.po @@ -1,116 +1,124 @@ -# -msgid "" -msgstr "Content-Type: text/plain; charset=utf-8\n" - -msgctxt "model:ir.message,text:msg_btype_asset" -msgid "Asset" -msgstr "Asset" - -msgctxt "view:cashbook.book:" -msgid "Asset" -msgstr "Asset" - -msgctxt "view:cashbook.book:" -msgid "Quantity" -msgstr "Quantity" - -msgctxt "view:cashbook.book:" -msgid "Current valuation of the investment" -msgstr "Current valuation of the investment" - -msgctxt "field:cashbook.book,asset:" -msgid "Asset" -msgstr "Asset" - -msgctxt "field:cashbook.book,quantity_digits:" -msgid "Digits" -msgstr "Digits" - -msgctxt "help:cashbook.book,quantity_digits:" -msgid "Quantity Digits" -msgstr "Quantity Digits" - -msgctxt "help:cashbook.book,asset_uomcat:" -msgid "UOM Category" -msgstr "UOM Category" - -msgctxt "field:cashbook.book,quantity_uom:" -msgid "UOM" -msgstr "UOM" - -msgctxt "field:cashbook.book,symbol:" -msgid "Symbol" -msgstr "Symbol" - -msgctxt "field:cashbook.book,asset_symbol:" -msgid "Symbol" -msgstr "Symbol" - -msgctxt "field:cashbook.book,quantity:" -msgid "Quantity" -msgstr "Quantity" - -msgctxt "help:cashbook.book,quantity:" -msgid "Quantity of assets until to date" -msgstr "Quantity of assets until to date" - -msgctxt "field:cashbook.book,quantity_all:" -msgid "Total Quantity" -msgstr "Total Quantity" - -msgctxt "help:cashbook.book,quantity_all:" -msgid "Total quantity of all assets" -msgstr "Total quantity of all assets" - -msgctxt "field:cashbook.book,current_value:" -msgid "Value" -msgstr "Value" - -msgctxt "help:cashbook.book,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.book,current_value_ref:" -msgid "Value (Ref.)" -msgstr "Value (Ref.)" - -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" - -msgctxt "field:cashbook.line,quantity:" -msgid "Quantity" -msgstr "Quantity" - -msgctxt "field:cashbook.line,quantity_symbol:" -msgid "Symbol" -msgstr "Symbol" - +# +msgid "" +msgstr "Content-Type: text/plain; charset=utf-8\n" + +msgctxt "model:ir.message,text:msg_btype_asset" +msgid "Asset" +msgstr "Asset" + +msgctxt "view:cashbook.book:" +msgid "Asset" +msgstr "Asset" + +msgctxt "view:cashbook.book:" +msgid "Quantity" +msgstr "Quantity" + +msgctxt "view:cashbook.book:" +msgid "Current valuation of the investment" +msgstr "Current valuation of the investment" + +msgctxt "field:cashbook.book,asset:" +msgid "Asset" +msgstr "Asset" + +msgctxt "field:cashbook.book,quantity_digits:" +msgid "Digits" +msgstr "Digits" + +msgctxt "help:cashbook.book,quantity_digits:" +msgid "Quantity Digits" +msgstr "Quantity Digits" + +msgctxt "help:cashbook.book,asset_uomcat:" +msgid "UOM Category" +msgstr "UOM Category" + +msgctxt "field:cashbook.book,quantity_uom:" +msgid "UOM" +msgstr "UOM" + +msgctxt "field:cashbook.book,symbol:" +msgid "Symbol" +msgstr "Symbol" + +msgctxt "field:cashbook.book,asset_symbol:" +msgid "Symbol" +msgstr "Symbol" + +msgctxt "field:cashbook.book,quantity:" +msgid "Quantity" +msgstr "Quantity" + +msgctxt "help:cashbook.book,quantity:" +msgid "Quantity of assets until to date" +msgstr "Quantity of assets until to date" + +msgctxt "field:cashbook.book,quantity_all:" +msgid "Total Quantity" +msgstr "Total Quantity" + +msgctxt "help:cashbook.book,quantity_all:" +msgid "Total quantity of all assets" +msgstr "Total quantity of all assets" + +msgctxt "field:cashbook.book,current_value:" +msgid "Value" +msgstr "Value" + +msgctxt "help:cashbook.book,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.book,current_value_ref:" +msgid "Value (Ref.)" +msgstr "Value (Ref.)" + +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" + +msgctxt "field:cashbook.line,quantity:" +msgid "Quantity" +msgstr "Quantity" + +msgctxt "field:cashbook.line,quantity_credit:" +msgid "Quantity Credit" +msgstr "Quantity Credit" + +msgctxt "field:cashbook.line,quantity_debit:" +msgid "Quantity Debit" +msgstr "Quantity Debit" + +msgctxt "field:cashbook.line,quantity_symbol:" +msgid "Symbol" +msgstr "Symbol" + diff --git a/tests/test_book.py b/tests/test_book.py index 0fc41f5..ad568d0 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -55,6 +55,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): """ pool = Pool() Book = pool.get('cashbook.book') + Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') Asset = pool.get('investment.asset') @@ -129,17 +130,24 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].amount, Decimal('2.5')) self.assertEqual(book.lines[0].quantity, Decimal('1.453')) + self.assertEqual(book.lines[0].quantity_credit, Decimal('1.453')) + 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[1].amount, Decimal('4.0')) self.assertEqual(book.lines[1].quantity, Decimal('3.3')) + self.assertEqual(book.lines[1].quantity_credit, Decimal('3.3')) + self.assertEqual(book.lines[1].quantity_debit, Decimal('0.0')) self.assertEqual(book.lines[1].quantity_digits, 3) self.assertEqual(book.lines[1].quantity_uom.symbol, 'u') self.assertEqual(book.symbol, '€/u') self.assertEqual(book.asset.rec_name, 'Product 1 | 2.8000 usd/u | 05/02/2022') + # wf --> check + Line.wfcheck(book.lines) + # check quantities at cashbook with Transaction().set_context({ 'qdate': date(2022, 5, 5), @@ -466,6 +474,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): @with_transaction() def test_assetbook_check_bookingtype_mvout(self): """ create cashbook + line, bookingtype 'mvout' + transfer from cash to depot (buy asset, pay from cash) """ pool = Pool() Book = pool.get('cashbook.book') @@ -537,7 +546,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(len(book.lines), 1) self.assertEqual(book.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open]') self.assertEqual(book.lines[0].state, 'check') + self.assertEqual(book.lines[0].bookingtype, 'mvout') self.assertEqual(book.lines[0].quantity, Decimal('1.5')) + self.assertEqual(book.lines[0].quantity_credit, Decimal('0.0')) + self.assertEqual(book.lines[0].quantity_debit, Decimal('1.5')) self.assertEqual(len(book.lines[0].references), 1) self.assertEqual(book.lines[0].reference, None) self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id) @@ -546,6 +558,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].rec_name, '05/01/2022|from|1.00 usd|Transfer Out [Book 1 | -1.00 usd | Open]') self.assertEqual(book2.lines[0].state, 'check') self.assertEqual(book2.lines[0].quantity, Decimal('1.5')) + self.assertEqual(book2.lines[0].quantity_credit, Decimal('1.5')) + self.assertEqual(book2.lines[0].quantity_debit, Decimal('0.0')) + self.assertEqual(book2.lines[0].bookingtype, 'mvin') + self.assertEqual(book2.lines[0].asset_rate, Decimal('0.6667')) self.assertEqual(book2.lines[0].reference.rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open]') self.assertEqual(len(book2.lines[0].references), 0) diff --git a/view/line_form.xml b/view/line_form.xml index a135d0b..03d0559 100644 --- a/view/line_form.xml +++ b/view/line_form.xml @@ -10,6 +10,11 @@ full copyright notices and license terms. -->