From b01e24b6aff606ce9f831512d9e6aa24ce71aad8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 18 Jan 2016 14:54:08 +0100 Subject: [PATCH] [FIX] account: company currency in payment The company currency should be the company currency of the invoice, not the company currency of the account journal linked to the payment. The following use case causes an issue: - invoice in GBP - journal of the invoice in AED - journal of the payment in CHF In this case, residual_company_signed will be considered to be in CHF while it was recorded in AED. opw-666595 --- addons/account/models/account_payment.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 5ea2b0bfd23..6da8085e961 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -87,10 +87,12 @@ class account_abstract_payment(models.AbstractModel): 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) + total = 0 + for inv in invoices: + if inv.company_currency_id != payment_currency: + total += inv.company_currency_id.with_context(date=self.payment_date).compute(inv.residual_company_signed, payment_currency) + else: + total += inv.residual_company_signed return abs(total)