From 91efa25bb78859121a7a0887e95c63aa7f7a6bc0 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Tue, 3 Nov 2009 08:08:58 +0100 Subject: [PATCH] [FIX] Residual amount into invoice is now correct in every case and avoid rounding trouble even if rating has changed bzr revid: joel.grandguillaume@camptocamp.com-20091103070858-86gtu8tzvztjuyt4 --- addons/account/invoice.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 606b42ee926..ca8b36fbdfe 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -107,19 +107,29 @@ class account_invoice(osv.osv): for inv in data_inv: debit = credit = 0.0 context.update({'date':inv.date_invoice}) + context_unreconciled=context.copy() for lines in inv.move_lines: + debit_tmp = lines.debit + credit_tmp = lines.credit # If currency conversion needed if inv.company_id.currency_id.id <> inv.currency_id.id: # If invoice paid, compute currency amount according to invoice date # otherwise, take the line date if not inv.reconciled: context.update({'date':lines.date}) - # Compute amount in currency - debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.debit, round=False,context=context) - credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.credit, round=False,context=context) + context_unreconciled.update({'date':lines.date}) + # If amount currency setted, compute for debit and credit in company currency + if lines.amount_currency < 0: + credit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + elif lines.amount_currency > 0: + debit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + # Then, recomput into invoice currency to avoid rounding trouble ! + debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, debit_tmp, round=False,context=context) + credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, credit_tmp, round=False,context=context) else: - debit += lines.debit - credit += lines.credit + debit+=debit_tmp + credit+=credit_tmp + if not inv.amount_total: result = 0.0 elif inv.type in ('out_invoice','in_refund'): @@ -128,7 +138,9 @@ class account_invoice(osv.osv): else: amount = debit-credit result = inv.amount_total - amount - res[inv.id] = result + # Use is_zero function to avoid rounding trouble => should be fixed into ORM + res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id,result) and result or 0.0 + return res def _get_lines(self, cr, uid, ids, name, arg, context=None):