From ff61bd63ace11e98165fcb3acbcd7bc71c3cfae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 27 Mar 2019 00:35:37 +0100 Subject: [PATCH] Update cash basis on reconciliation The reconciled lines must be added to the payment amount and reconciliation should trigger the update of cash basis via process call. issue8207 review249121002 --- account.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/account.py b/account.py index 92b729b1de..195c6ccca7 100644 --- a/account.py +++ b/account.py @@ -249,7 +249,11 @@ class Invoice(metaclass=PoolMeta): ratio = 0 else: payment_amount = sum( - l.debit - l.credit for l in self.payment_lines) + l.debit - l.credit for l in self.payment_lines + if not l.reconciliation) + payment_amount -= sum( + l.debit - l.credit for l in self.lines_to_pay + if l.reconciliation) if amount: ratio = abs(payment_amount / amount) else: @@ -259,21 +263,35 @@ class Invoice(metaclass=PoolMeta): @classmethod def write(cls, *args): - pool = Pool() - TaxLine = pool.get('account.tax.line') - Date = pool.get('ir.date') - Period = pool.get('account.period') - super(Invoice, cls).write(*args) invoices = [] actions = iter(args) for records, values in zip(actions, actions): - if ('payment_lines' in values - or values.get('state') in {'paid', 'cancel', 'posted'}): + if 'payment_lines' in values: invoices.extend(records) invoices = cls.browse(sum(args[0:None:2], [])) invoices = [i for i in invoices if i.move] + cls._update_tax_cash_basis(invoices) + + @classmethod + def process(cls, invoices): + super(Invoice, cls).process(invoices) + cls._update_tax_cash_basis(invoices) + + @classmethod + @ModelView.button + @Workflow.transition('cancel') + def cancel(cls, invoices): + super(Invoice, cls).cancel(invoices) + cls._update_tax_cash_basis(invoices) + + @classmethod + def _update_tax_cash_basis(cls, invoices): + pool = Pool() + TaxLine = pool.get('account.tax.line') + Date = pool.get('ir.date') + Period = pool.get('account.period') # Call update_cash_basis grouped per period and ratio only because # group_cash_basis_key already group per move_line.