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):