[FIX] account: corrected move balance check - rounding correctly based on price_accuracy
authorOlivier Dony <odo@openerp.com>
Fri, 23 Apr 2010 12:27:09 +0000 (14:27 +0200)
committerOlivier Dony <odo@openerp.com>
Fri, 23 Apr 2010 12:27:09 +0000 (14:27 +0200)
lp bug: https://launchpad.net/bugs/452854 fixed
lp bug: https://launchpad.net/bugs/513278 fixed

bzr revid: odo@openerp.com-20100423122709-hpn2olakb0c8tx6y

addons/account/account.py

index 59189b3..79540fe 100644 (file)
@@ -1088,7 +1088,13 @@ class account_move(osv.osv):
                     if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id or line.currency_id):
                         raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name)))
 
-            if abs(amount) < 10 ** -int(config['price_accuracy']):
+            # Check that the move balances, the tolerance for debit/credit must
+            # be smaller than the smallest value according to price accuracy
+            # (hence the +1 below)
+            # Example:
+            #    difference == 0.01 is OK iff price_accuracy <= 1!
+            #    difference == 0.0001 is OK iff price_accuracy <= 3!
+            if abs(amount) < 10 ** -(int(config['price_accuracy'])+1):
                 if not len(line_draft_ids):
                     continue
                 self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {