[FIX] account: exchange difference date and amount

The use case is the following: the currency of a customer invoice (e.g.
EUR) is different from the currency of the company (e.g. USD). An
invoice is created in EUR, and a payment is done in EUR on the
receivable account which is in EUR.

Between the invoice date (e.g. 2015-01-01) and the payment date (e.g.
2015-02-01), the rate has changed. The reconciliation between the
invoice and the payment is done afterwards, for example 2015-03-01.

When the write-off related to the exchange difference is created:
- the date should be the max date between payment and invoice if the
  corresponding fiscal year is not closed (otherwise, today's date).
- the amount currency on the receivable/payable account should be zero,
  since the amount currency on the foreign exchange account is zero.

opw-659289
This commit is contained in:
Nicolas Martinelli
2016-01-08 08:11:24 +01:00
parent 54be29f0bc
commit ef6116bfb5
+11 -1
View File
@@ -1194,7 +1194,16 @@ class AccountPartialReconcile(models.Model):
if not self.company_id.expense_currency_exchange_account_id.id:
raise UserError(_("You should configure the 'Loss Exchange Rate Account' in the accounting settings, to manage automatically the booking of accounting entries related to differences between exchange rates."))
amount_diff = rec.company_id.currency_id.round(rec.amount_currency * rate_diff)
move = rec.env['account.move'].create({'journal_id': rec.company_id.currency_exchange_journal_id.id, 'rate_diff_partial_rec_id': rec.id})
move_vals = {'journal_id': rec.company_id.currency_exchange_journal_id.id, 'rate_diff_partial_rec_id': rec.id}
# The move date should be the maximum date between payment and invoice (in case
# of payment in advance). However, we should make sure the move date is not
# recorded after the end of year closing.
move_date = max(rec.debit_move_id.date, rec.credit_move_id.date)
if move_date > rec.company_id.fiscalyear_lock_date:
move_vals['date'] = move_date
move = rec.env['account.move'].create(move_vals)
line_to_reconcile = rec.env['account.move.line'].with_context(check_move_validity=False).create({
'name': _('Currency exchange rate difference'),
'debit': amount_diff < 0 and -amount_diff or 0.0,
@@ -1202,6 +1211,7 @@ class AccountPartialReconcile(models.Model):
'account_id': rec.debit_move_id.account_id.id,
'move_id': move.id,
'currency_id': rec.currency_id.id,
'amount_currency': 0.0,
})
rec.env['account.move.line'].create({
'name': _('Currency exchange rate difference'),