[FIX] account: partial payment reconciliation

When processing a partial reconciliation in a foreign currency, a
currency exchange difference might be generated during the
reconciliation process (see OPW for a detailed use case).

This prevents the user to process the reconciliation since he will get
the error: 'You have to provide an account for the write off/exchange
difference entry.'

The fix is to use the company-related foreign echange gain and loss
accounts automatically to book this difference.

opw-687975
This commit is contained in:
Nicolas Martinelli 2016-11-22 11:56:51 +01:00
parent 623d61872d
commit cd440312ce
2 changed files with 26 additions and 9 deletions

View File

@ -920,7 +920,8 @@ class account_bank_statement_line(osv.osv):
move_line_pairs_to_reconcile.append([new_aml_id, counterpart_move_line_id])
# Reconcile
for pair in move_line_pairs_to_reconcile:
aml_obj.reconcile_partial(cr, uid, pair, context=context)
# DO NOT FORWARD PORT
aml_obj.reconcile_partial(cr, uid, pair, context=dict(context, bs_move_id=move_id))
# Mark the statement line as reconciled
self.write(cr, uid, id, {'journal_entry_id': move_id}, context=context)

View File

@ -1004,6 +1004,12 @@ class account_move_line(osv.osv):
if (not currency_obj.is_zero(cr, uid, account.company_id.currency_id, writeoff)) or \
(account.currency_id and (not currency_obj.is_zero(cr, uid, account.currency_id, currency))):
# DO NOT FORWARD PORT
if not writeoff_acc_id:
if writeoff > 0:
writeoff_acc_id = account.company_id.expense_currency_exchange_account_id.id
else:
writeoff_acc_id = account.company_id.income_currency_exchange_account_id.id
if not writeoff_acc_id:
raise osv.except_osv(_('Warning!'), _('You have to provide an account for the write off/exchange difference entry.'))
if writeoff > 0:
@ -1057,14 +1063,24 @@ class account_move_line(osv.osv):
'amount_currency': amount_currency_writeoff and amount_currency_writeoff or (account.currency_id.id and currency or 0.0)
})
]
writeoff_move_id = move_obj.create(cr, uid, {
'period_id': writeoff_period_id,
'journal_id': writeoff_journal_id,
'date':date,
'state': 'draft',
'line_id': writeoff_lines
})
# DO NOT FORWARD PORT
# In some exceptional situations (partial payment from a bank statement in foreign
# currency), a write-off can be introduced at the very last moment due to currency
# conversion. We record it on the bank statement account move.
if context.get('bs_move_id'):
writeoff_move_id = context['bs_move_id']
for l in writeoff_lines:
self.create(cr, uid, dict(l[2], move_id=writeoff_move_id), dict(context, novalidate=True))
if not move_obj.validate(cr, uid, writeoff_move_id, context=context):
raise osv.except_osv(_('Error!'), _('You cannot validate a non-balanced entry.'))
else:
writeoff_move_id = move_obj.create(cr, uid, {
'period_id': writeoff_period_id,
'journal_id': writeoff_journal_id,
'date':date,
'state': 'draft',
'line_id': writeoff_lines
})
writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', '=', account_id)])
if account_id == writeoff_acc_id: