From ec7109c9194622fd20ad1f2ff7ab2f239e0194ec Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 31 Jul 2018 14:38:44 +0200 Subject: [PATCH] [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 --- addons/account/models/account_payment.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index e0b6864b0f7..7d1231ece2e 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -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)