From dd47b6f5bccfb43ee6fabb81effd16c940a020e0 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 5 May 2015 18:12:46 +0200 Subject: [PATCH] [FIX] account: Exchanges rates gain/loss during reconciliations When processing the reconciliation of a bank statement within the company currency with an invoice in a foreign currency, avoid to recompute the bank statement debit / credit within the currency rate at the time of the invoice when the `amount_currency` of the bank statement line and the `amount_currency` of the invoice move line are the same (while having the invoice move line and the bank statement move line in the same currency, and having the bank statement currency and the company currency the same), to prevent gain/loss exchanges during currencies conversion. Computing the amount of the statement line within the currency of the invoice is useful to compute the difference of amount paid within the company currency when a change of currency rates occured between the invoice date and the date of the payment. Nevertheless, recomputing the amount in the currency of the company is useless when the payment currency and the company currency are the same, and the amount of the invoice and the statement in the foreign currency are identical, since the amount is already computed, within the debit/credit field of the invoice move line. Besides, this prevents gain/loss changes. opw-631748 opw-632133 opw-631895 closes #6559 --- addons/account/account_bank_statement.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index b4ccea8ba20..4a9c1127410 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -20,6 +20,7 @@ ############################################################################## from openerp.osv import fields, osv +from openerp.tools import float_is_zero from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp from openerp.report import report_sxw @@ -793,8 +794,13 @@ class account_bank_statement_line(osv.osv): if mv_line_dict.get('counterpart_move_line_id'): #post an account line that use the same currency rate than the counterpart (to balance the account) and post the difference in another line ctx['date'] = mv_line.date - debit_at_old_rate = currency_obj.compute(cr, uid, st_line_currency.id, company_currency.id, mv_line_dict['debit'], context=ctx) - credit_at_old_rate = currency_obj.compute(cr, uid, st_line_currency.id, company_currency.id, mv_line_dict['credit'], context=ctx) + if mv_line.currency_id.id == mv_line_dict['currency_id'] \ + and float_is_zero(mv_line.amount_currency - abs(mv_line_dict['amount_currency']), precision_rounding=mv_line.currency_id.rounding): + debit_at_old_rate = mv_line.credit + credit_at_old_rate = mv_line.debit + else: + debit_at_old_rate = currency_obj.compute(cr, uid, st_line_currency.id, company_currency.id, mv_line_dict['debit'], context=ctx) + credit_at_old_rate = currency_obj.compute(cr, uid, st_line_currency.id, company_currency.id, mv_line_dict['credit'], context=ctx) mv_line_dict['credit'] = credit_at_old_rate mv_line_dict['debit'] = debit_at_old_rate if debit_at_old_rate - debit_at_current_rate: