[FIX] account: reconcile over-amount bank statements in foreign currencies

When a bank statement reconciles its lines with payment using a foreign currency,
there is a mix up of values between the currency set in bank statement and payment against the company currency.

Current Behavior

Company Currency: MXN
Bank Statement Currency: USD
Payment Currency: USD
Current Rate 0.05130836

1) Generate a bank statement with 990 USD.
2) Generate a payment with 1000 USD.
3) Reconcile the bank statement against the payment.

The reconcile process generates a payment with the difference (10 USD)
Before this commit, this automatically created payment took an erroneous amount,
Taking a currency-converted amount where it should not have

It was happening because the reconcile process uses the debit or credit value(Local Currency)
against bank statement line amount (Foreign Currency).

After this commit, the amount set in the generated payment because of the difference is 10 USD.

closed odoo#30623

closes odoo/odoo#30779
This commit is contained in:
Jose Morales
2019-02-11 17:06:14 +00:00
committed by Luis González
parent 2503a89e9e
commit 2d2fe7f555
2 changed files with 12 additions and 1 deletions
@@ -557,8 +557,11 @@ class AccountBankStatementLine(models.Model):
# Fully reconciled moves are just linked to the bank statement
total = self.amount
currency = self.currency_id or statement_currency
for aml_rec in payment_aml_rec:
total -= aml_rec.debit - aml_rec.credit
balance = aml_rec.amount_currency if aml_rec.currency_id else aml_rec.balance
aml_currency = aml_rec.currency_id or aml_rec.company_currency_id
total -= aml_currency._convert(balance, currency, aml_rec.company_id, aml_rec.date)
aml_rec.with_context(check_move_validity=False).write({'statement_line_id': self.id})
counterpart_moves = (counterpart_moves | aml_rec.move_id)
if aml_rec.journal_id.post_at_bank_rec and aml_rec.payment_id and aml_rec.move_id.state == 'draft':
@@ -529,6 +529,14 @@ class TestReconciliation(AccountingTestCase):
self.diff_income_account.id: {'debit': 0.0, 'credit': 3.27, 'amount_currency': -5, 'currency_id': self.currency_usd_id},
self.account_rcv.id: {'debit': 0.0, 'credit': 52.33, 'amount_currency': -80, 'currency_id': self.currency_usd_id},
}
payments = bank_stmt_aml.mapped('payment_id')
# creation and reconciliation of the over-amount statement
# has created an another payment
self.assertEqual(len(payments), 2)
# Check amount of second, automatically created payment
self.assertEqual((payments - payment).amount, 5)
for aml in bank_stmt_aml:
line = lines[aml.account_id.id]
if type(line) == list: