[IMP] account: use float_compare for taxes
authorMartin Trigaux <mat@openerp.com>
Fri, 26 Sep 2014 14:55:41 +0000 (16:55 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 26 Sep 2014 14:57:28 +0000 (16:57 +0200)
Avoiding some python float representation errors

addons/account/account_invoice.py

index 1e4bc7a..9baa3f7 100644 (file)
@@ -27,6 +27,7 @@ import openerp.exceptions
 from openerp import netsvc, SUPERUSER_ID
 from openerp import pooler
 from openerp.osv import fields, osv, orm
+from openerp.tools import float_compare
 from openerp.tools.translate import _
 
 class account_invoice(osv.osv):
@@ -826,7 +827,8 @@ class account_invoice(osv.osv):
                 if not key in compute_taxes:
                     raise osv.except_osv(_('Warning!'), _('Global taxes defined, but they are not in invoice lines !'))
                 base = compute_taxes[key]['base']
-                if abs(base - tax.base) > company_currency.rounding:
+                precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
+                if float_compare(abs(base - tax.base), company_currency.rounding, precision_rounding=precision) == 1:
                     raise osv.except_osv(_('Warning!'), _('Tax base different!\nClick on compute to update the tax base.'))
             for key in compute_taxes:
                 if not key in tax_key: