Skip to content

Commit

Permalink
[FIX] account: Wrong payment amount in multi-currency
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simongoffin committed Aug 2, 2018
1 parent 8c07fd3 commit ec7109c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions addons/account/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,26 @@ def _onchange_payment_type(self):

@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)
Expand Down

0 comments on commit ec7109c

Please sign in to comment.