diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 56b30800e65..b120da9f3cc 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -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) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 143c8ff5468..c4042625691 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -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: