From fa2f7b86bff9cecad73ef14fdc1480c7bca2a584 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Thu, 16 Oct 2014 17:23:51 +0200 Subject: [PATCH] [FIX] product: remove digits_precision from uom factor fields Remove the hardcoded precision of 12 on factor and factor_inv, to use the complete natural precision of NUMERIC types, preserving all significant digits. e.g. a UoM with a factor_inv of 6.0 used to be computed as: factor_inv: 6.0 -> factor: 0.166666666667 (1.0/6.0, rounded to 12 digits) -> factor_inv: 5.999999999988 (1.0/factor) which could lead to errors such 12*0.166666666667 = 2.000000000004 instead of 2.0 Slightly changed the way the ORM handles float fields to allow setting `digits=0` as a way to explicitly require a NUMERIC value but without enforcing/rounding the values at the ORM level, i.e. a truly full-precision field. NUMERIC type has unlimited precision but is less efficient so should not be used as the default behaviour, which is why we keep float8 as an alternative. Modified the view to display the product UOM factor with a 5 digits value by default. This value is for usability purpose only, the field still accepts bigger precision, by setting the `digits` option on the field in the form view. This change is safe in a stable series, the `digits=0` alternative is treated the same as the default `digits=None` everywhere in the framework, except when creating the database field. --- addons/product/product.py | 4 ++-- addons/product/product_view.xml | 4 ++-- openerp/osv/orm.py | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 7a36507aa79..ff0a6a770d7 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -132,10 +132,10 @@ class product_uom(osv.osv): 'name': fields.char('Unit of Measure', size=64, required=True, translate=True), 'category_id': fields.many2one('product.uom.categ', 'Category', required=True, ondelete='cascade', help="Conversion between Units of Measure can only occur if they belong to the same category. The conversion will be made based on the ratios."), - 'factor': fields.float('Ratio', required=True,digits=(12, 12), + 'factor': fields.float('Ratio', required=True, digits=0, # force NUMERIC with unlimited precision help='How much bigger or smaller this unit is compared to the reference Unit of Measure for this category:\n'\ '1 * (reference unit) = ratio * (this unit)'), - 'factor_inv': fields.function(_factor_inv, digits=(12,12), + 'factor_inv': fields.function(_factor_inv, digits=0, # force NUMERIC with unlimited precision fnct_inv=_factor_inv_write, string='Ratio', help='How many times this Unit of Measure is bigger than the reference Unit of Measure in this category:\n'\ diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index 26bc294e436..7b4539e7dd3 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -421,8 +421,8 @@