diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 94567b81069..35e75ff7959 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -921,7 +921,22 @@ class AccountBankStatementLine(models.Model): aml_dict['currency_id'] = statement_currency.id # Create write-offs + # When we register a payment on an invoice, the write-off line contains the amount + # currency if all related invoices have the same currency. We apply the same logic in + # the manual reconciliation. + counterpart_aml = self.env['account.move.line'] + for aml_dict in counterpart_aml_dicts: + counterpart_aml |= aml_dict.get('move_line', self.env['account.move.line']) + new_aml_currency = False + if counterpart_aml\ + and len(counterpart_aml.mapped('currency_id')) == 1\ + and counterpart_aml[0].currency_id\ + and counterpart_aml[0].currency_id != company_currency: + new_aml_currency = counterpart_aml[0].currency_id for aml_dict in new_aml_dicts: + if new_aml_currency and not aml_dict.get('currency_id'): + aml_dict['currency_id'] = new_aml_currency.id + aml_dict['amount_currency'] = company_currency.with_context(ctx).compute(aml_dict['debit'] - aml_dict['credit'], new_aml_currency) aml_obj.with_context(check_move_validity=False).create(aml_dict) # Create counterpart move lines and reconcile them diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 6b8c98a6712..9e98495e8a5 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -244,7 +244,7 @@ class TestReconciliation(AccountingTestCase): self.check_results(bank_stmt.move_line_ids, { self.account_euro.id: {'debit': 40.0, 'credit': 0.0, 'amount_currency': 0, 'currency_id': False}, self.account_rcv.id: {'debit': 0.0, 'credit': 32.7, 'amount_currency': -41.97, 'currency_id': self.currency_usd_id, 'currency_diff': 0, 'amount_currency_diff': -8.03}, - self.diff_income_account.id: {'debit': 0.0, 'credit': 7.3, 'amount_currency': 0, 'currency_id': False}, + self.diff_income_account.id: {'debit': 0.0, 'credit': 7.3, 'amount_currency': -9.37, 'currency_id': self.currency_usd_id}, }) # The invoice should be paid, as the payments totally cover its total