From 7b4e8cbbf8c26cbf98db92a779672c4b9361870f Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 24 Sep 2012 12:33:07 +0200 Subject: [PATCH 1/2] [IMP] product: added constraints to make sure that the decimal precision of 'Account' is greater than the rounding factor of the company's main currency bzr revid: qdp-launchpad@openerp.com-20120924103307-4sdx61qxfy6lak2e --- addons/product/product.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/addons/product/product.py b/addons/product/product.py index ab282e722c0..144aa28c458 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -897,4 +897,43 @@ class pricelist_partnerinfo(osv.osv): } _order = 'min_quantity asc' pricelist_partnerinfo() + +class res_currency(osv.osv): + _inherit = 'res.currency' + + def _check_main_currency_rounding(self, cr, uid, ids, context=None): + cr.execute('SELECT digits FROM decimal_precision WHERE name like %s',('Account',)) + digits = cr.fetchone() + if len(digits): + digits = digits[0] + main_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id + for currency_id in ids: + if currency_id == main_currency.id: + if main_currency.rounding < 10 ** -digits: + return False + return True + + _constraints = [ + (_check_main_currency_rounding, 'Error! You cannot define a rounding factor for the company\'s main currency that is smaller than the decimal precision of \'Account\'.', ['rounding']), + ] + +class decimal_precision(osv.osv): + _inherit = 'decimal.precision' + + def _check_main_currency_rounding(self, cr, uid, ids, context=None): + cr.execute('SELECT id, digits FROM decimal_precision WHERE name like %s',('Account',)) + res = cr.fetchone() + if len(res): + account_precision_id, digits = res + main_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id + for decimal_precision in ids: + if decimal_precision == account_precision_id: + if main_currency.rounding < 10 ** -digits: + return False + return True + + _constraints = [ + (_check_main_currency_rounding, 'Error! You cannot define the decimal precision of \'Account\' as greater than the rounding factor of the company\'s main currency', ['digits']), + ] + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 29badc35a54e00f0ca0d516473eb82016d2b9355 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 24 Sep 2012 13:16:41 +0200 Subject: [PATCH 2/2] [FIX] product: 'Nonetype object has no len()' error fixed in newly added constraints for decimal precision of 'Account' <= company's main currency rounding bzr revid: qdp-launchpad@openerp.com-20120924111641-9papztx074vdbrpq --- addons/product/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 144aa28c458..df0ab9122c2 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -904,7 +904,7 @@ class res_currency(osv.osv): def _check_main_currency_rounding(self, cr, uid, ids, context=None): cr.execute('SELECT digits FROM decimal_precision WHERE name like %s',('Account',)) digits = cr.fetchone() - if len(digits): + if digits and len(digits): digits = digits[0] main_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id for currency_id in ids: @@ -923,7 +923,7 @@ class decimal_precision(osv.osv): def _check_main_currency_rounding(self, cr, uid, ids, context=None): cr.execute('SELECT id, digits FROM decimal_precision WHERE name like %s',('Account',)) res = cr.fetchone() - if len(res): + if res and len(res): account_precision_id, digits = res main_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id for decimal_precision in ids: