From 56fa7a078bcd6756d8d9b6ef252269022fd01338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Sun, 28 Nov 2021 18:56:16 +0100 Subject: [PATCH] Add the payment amount to invoice's amount_to_pay when the payment line is unreconciled issue10757 review371951002 --- CHANGELOG | 2 ++ account.py | 9 ++++----- payment.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a28db42432..f18b8fd178 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add amount_line_paid property on payments + Version 6.2.0 - 2021-11-01 * Bug fixes (see mercurial logs for details) * Add wizard to create direct debit for configured parties diff --git a/account.py b/account.py index df6b0f47e2..ad69ec5d30 100644 --- a/account.py +++ b/account.py @@ -557,10 +557,9 @@ class Invoice(metaclass=PoolMeta): continue payment_amount = Decimal(0) for payment in line.payments: - if payment.state != 'failed': - with Transaction().set_context(date=payment.date): - payment_amount += Currency.compute( - payment.currency, payment.amount, - invoice.currency) + with Transaction().set_context(date=payment.date): + payment_amount += Currency.compute( + payment.currency, payment.amount_line_paid, + invoice.currency) amounts[invoice.id] -= payment_amount return amounts diff --git a/payment.py b/payment.py index fd34db4e17..33a2fc8f91 100644 --- a/payment.py +++ b/payment.py @@ -363,6 +363,16 @@ class Payment(Workflow, ModelSQL, ModelView): ('failed', 'Failed'), ], 'State', readonly=True, select=True) + @property + def amount_line_paid(self): + if self.state != 'failed': + if self.line.second_currency: + payment_amount = abs(self.line.amount_second_currency) + else: + payment_amount = abs(self.line.credit - self.line.debit) + return max(min(self.amount, payment_amount), 0) + return Decimal(0) + @classmethod def __setup__(cls): super(Payment, cls).__setup__()