[FIX] account: write-off currency
In a multi-currency environment, company currency is USD
- Create an invoice of 100 EUR, corresponding to 65 USD
- Register a payment directly from the invoice (button "Register
Payment") of 60 USD. Choose "Mark invoice as fully paid".
- The write-off line contains the amount in the invoice currency (field
`amount_currency` filled in.
This was introduced in commit 003f2ee9b.
On the other hand:
- Create an invoice of 100 EUR, corresponding to 65 USD
- Create a bank statement of 60 USD.
- Proceed to reconciliation, and create a write-off line of 5 USD.
- In this case, the write-off line does not contain the amount in the
invoice currency.
The user expects the same behavior in both cases, so we introduce the
amount currency in the second case.
opw-690784
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user