diff --git a/line.py b/line.py index d0dfc75..ad1ea15 100644 --- a/line.py +++ b/line.py @@ -672,27 +672,24 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView): else: return 2 - @fields.depends('id', 'date', 'cashbook', \ - '_parent_cashbook.id', 'reconciliation', \ - '_parent_reconciliation.start_amount',\ - '_parent_reconciliation.state') - def on_change_with_balance(self, name=None): - """ compute balance until current line, with current sort order, - try to use a reconciliation as start to speed up calculation + @classmethod + def get_balance_of_line(cls, line, field_name='amount', credit_name='credit', debit_name='debit'): + """ get balance of current line, + try to speed up by usage of last reconcilitaion """ pool = Pool() Reconciliation = pool.get('cashbook.recon') - Line = pool.get('cashbook.line') + Line2 = pool.get('cashbook.line') def get_from_last_recon(line2): """ search last reconciliation in state 'done', generate query """ query2 = [] - end_amount = None + end_value = None recons = Reconciliation.search([ - ('cashbook.id', '=', self.cashbook.id), + ('cashbook.id', '=', line.cashbook.id), ('date_to', '<=', line2.date), ('state', '=', 'done'), ], order=[('date_from', 'DESC')], limit=1) @@ -705,42 +702,56 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView): ('reconciliation.id', '!=', recons[0]), ], ]) - end_amount = recons[0].end_amount - return (query2, end_amount) + end_value = getattr(recons[0], 'end_%s' % field_name) + return (query2, end_value) - if self.cashbook: + if line.cashbook: query = [ - ('cashbook.id', '=', self.cashbook.id), + ('cashbook.id', '=', line.cashbook.id), ] balance = Decimal('0.0') # get existing reconciliation, starting before current line # this will speed up calculation of by-line-balance - if self.date is not None: - if self.reconciliation: - if self.reconciliation.state == 'done': + if line.date is not None: + if line.reconciliation: + if line.reconciliation.state == 'done': query.append( - ('reconciliation.id', '=', self.reconciliation.id), + ('reconciliation.id', '=', line.reconciliation.id), ) - balance = self.reconciliation.start_amount + balance = getattr(line.reconciliation, 'start_%s' % field_name) else : - (query2, balance2) = get_from_last_recon(self) + (query2, balance2) = get_from_last_recon(line) query.extend(query2) if balance2 is not None: balance = balance2 else : - (query2, balance2) = get_from_last_recon(self) + (query2, balance2) = get_from_last_recon(line) query.extend(query2) if balance2 is not None: balance = balance2 - lines = Line.search(query) - for line in lines: - balance += line.credit - line.debit - if line.id == self.id: + lines = Line2.search(query) + for line3 in lines: + balance += getattr(line3, credit_name) - getattr(line3, debit_name) + if line3.id == line.id: break return balance + @fields.depends('id', 'date', 'cashbook', \ + '_parent_cashbook.id', 'reconciliation', \ + '_parent_reconciliation.start_amount',\ + '_parent_reconciliation.state') + def on_change_with_balance(self, name=None): + """ compute balance until current line, with current sort order, + try to use a reconciliation as start to speed up calculation + """ + Line2 = Pool().get('cashbook.line') + return Line2.get_balance_of_line(self, + field_name='amount', + credit_name='credit', + debit_name='debit') + @classmethod def clear_by_bookingtype(cls, values, line=None): """ clear some fields by value of bookingtype diff --git a/locale/de.po b/locale/de.po index b533724..dec100b 100644 --- a/locale/de.po +++ b/locale/de.po @@ -1454,6 +1454,10 @@ msgctxt "field:cashbook.recon,predecessor:" msgid "Predecessor" msgstr "Vorgänger" +msgctxt "field:cashbook.recon,feature:" +msgid "Feature" +msgstr "Merkmal" + ############################# # cashbook.runrepbook.start # diff --git a/locale/en.po b/locale/en.po index 0326dff..d0c175f 100644 --- a/locale/en.po +++ b/locale/en.po @@ -1378,6 +1378,10 @@ msgctxt "field:cashbook.recon,predecessor:" msgid "Predecessor" msgstr "Predecessor" +msgctxt "field:cashbook.recon,feature:" +msgid "Feature" +msgstr "Feature" + msgctxt "model:cashbook.runrepbook.start,name:" msgid "Cashbook Report" msgstr "Cashbook Report" diff --git a/reconciliation.py b/reconciliation.py index 143813c..18b5a60 100644 --- a/reconciliation.py +++ b/reconciliation.py @@ -40,6 +40,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView): model_name='cashbook.book', ondelete='CASCADE', readonly=True) date = fields.Date(string='Date', required=True, select=True, states=STATES, depends=DEPENDS) + feature = fields.Function(fields.Char(string='Feature', readonly=True, + states={'invisible': True}), 'on_change_with_feature') date_from = fields.Date(string='Start Date', required=True, @@ -342,6 +344,13 @@ class Reconciliation(Workflow, ModelSQL, ModelView): IrDate = Pool().get('ir.date') return IrDate.today() + @fields.depends('cashbook', '_parent_cashbook.btype') + def on_change_with_feature(self, name=None): + """ get feature-set + """ + if self.cashbook: + return self.cashbook.btype.feature + @fields.depends('cashbook', '_parent_cashbook.id', 'date_from') def on_change_with_predecessor(self, name=None): """ get predecessor @@ -366,7 +375,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView): @fields.depends('cashbook', '_parent_cashbook.currency') def on_change_with_currency_digits(self, name=None): - """ currency of cashbook + """ currency-digits of cashbook """ if self.cashbook: return self.cashbook.currency.digits diff --git a/tests/test_reconciliation.py b/tests/test_reconciliation.py index 98b77e4..f294cf3 100644 --- a/tests/test_reconciliation.py +++ b/tests/test_reconciliation.py @@ -231,6 +231,7 @@ class ReconTestCase(ModuleTestCase): }]) self.assertEqual(book.name, 'Book 1') self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]') + self.assertEqual(book.reconciliations[0].feature, 'gen') Reconciliation.wfcheck(list(book.reconciliations)) self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]') diff --git a/view/recon_form.xml b/view/recon_form.xml index 53c6ee3..478fba6 100644 --- a/view/recon_form.xml +++ b/view/recon_form.xml @@ -33,4 +33,6 @@ full copyright notices and license terms. --> + +