diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 4f918c1846b..7195170a86a 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -81,13 +81,16 @@ class account_abstract_payment(models.AbstractModel): def _compute_total_invoices_amount(self): """ Compute the sum of the residual of invoices, expressed in the payment currency """ - total = 0 payment_currency = self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id - for inv in self._get_invoices(): - total += inv.residual_company_signed - company_currency = self.company_id.currency_id if self.company_id else self.env.user.company_id.currency_id - if company_currency and company_currency != payment_currency: - total = company_currency.with_context(date=self.payment_date).compute(total, payment_currency) + invoices = self._get_invoices() + + if all(inv.currency_id == payment_currency for inv in invoices): + total = sum(invoices.mapped('residual_signed')) + else: + total = sum(invoices.mapped('residual_company_signed')) + company_currency = self.company_id.currency_id if self.company_id else self.env.user.company_id.currency_id + if company_currency and company_currency != payment_currency: + total = company_currency.with_context(date=self.payment_date).compute(total, payment_currency) return abs(total)