From 69a898cf8bb066e884039c1f239aa38ef6ccfa99 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Thu, 23 Aug 2018 16:24:09 +0200 Subject: [PATCH] [IMP] uom: add constraints to force reference factor When importing big amount of data, user can import a list of uom. There is no constraint in Odoo to force the factor to be equal to 1.0 for the reference UoM in a category. Onchange is not enought to ensure that constraint, so this commit adds one in SQL for data intergrity and to avoid problem in '_compute_quantity' method. --- addons/uom/models/uom_uom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py index d57a1b67b0d..99e2375cfe8 100644 --- a/addons/uom/models/uom_uom.py +++ b/addons/uom/models/uom_uom.py @@ -59,7 +59,8 @@ class UoM(models.Model): _sql_constraints = [ ('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!'), - ('rounding_gt_zero', 'CHECK (rounding>0)', 'The rounding precision must be strictly positive.') + ('rounding_gt_zero', 'CHECK (rounding>0)', 'The rounding precision must be strictly positive.'), + ('factor_reference_is_one', "CHECK((uom_type = 'reference' AND factor = 1.0) OR (uom_type != 'reference'))", "The reference unit must have a conversion factor equal to 1.") ] @api.one