Skip to content
Snippets Groups Projects
Commit a98d1f51 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] account: do not convert amount

In a multi-currency environment, the difference amount computed will be
affected by the exchange rate change. In other words, if the exchange
rate changes between the invoice date and the payment date, this
difference will be reflected in the difference amount. For example:
- Company currency is USD, invoice currency is EUR
- At invoice date, 1 USD = 1 EUR
- At payment date, 1 USD = 0.9 EUR
- An invoice of 1000 EUR is created
- A payment of 1000 EUR is done

Without this fix, a payment difference of -100 EUR is shown. The reason
is that at invoice date, we expect a payment corresponding to 1000 USD,
which is equal to 900 EUR at payment date.

This fix doesn't do any currency conversion if the payment currency is
the same than the invoice currency, to prevent any exchange rate
difference shown. Indeed, if an invoice is 1000 EUR, a user expects that
a payment of 1000 EUR will not show any payment difference.

Note that this doesn't fix the payment difference amount when an invoice
in a given currency is paid in another currency.

opw-658177
parent 52fa7814
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment