[FIX] account: Wrong payment amount in multi-currency

Steps to reproduce:

- activate the EUR currency

- set a currency rate 1 USD = 1.2 EUR

- create a Bank journal in EUR with a EUR account

- create a Vendor Bill in EUR for 1200 EUR in total

- go in the Vendor Bill list view (Accounting > Purchase > Vendor Bills)

- select the created Vendor Bill

- click "Register Payment" in the action menu

- select the EUR Bank journal you created

Bug:

The payment amount is 1000 EUR instead of 1200 EUR.

opw:1870351
This commit is contained in:
Goffin Simon
2018-08-02 16:27:34 +02:00
parent 8c07fd3c5a
commit ec7109c919
+10 -2
View File
@@ -113,18 +113,26 @@ class account_register_payments(models.TransientModel):
@api.model
def _compute_payment_amount(self, invoice_ids):
payment_currency = self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id
payment_currency = self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id or invoice_ids and invoice_ids[0].currency_id
total = 0
for inv in invoice_ids:
if inv.currency_id == payment_currency:
total += MAP_INVOICE_TYPE_PAYMENT_SIGN[inv.type] * inv.residual_company_signed
total += MAP_INVOICE_TYPE_PAYMENT_SIGN[inv.type] * inv.residual_signed
else:
amount_residual = inv.company_currency_id.with_context(date=self.payment_date).compute(
inv.residual_company_signed, payment_currency)
total += MAP_INVOICE_TYPE_PAYMENT_SIGN[inv.type] * amount_residual
return total
@api.onchange('journal_id')
def _onchange_journal(self):
res = super(account_register_payments, self)._onchange_journal()
active_ids = self._context.get('active_ids')
invoices = self.env['account.invoice'].browse(active_ids)
self.amount = abs(self._compute_payment_amount(invoices))
return res
@api.model
def default_get(self, fields):
rec = super(account_register_payments, self).default_get(fields)