From e0ed50a724eb129451d98d93e7365b4b117cfd0a Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 5 Mar 2018 09:31:25 +0100 Subject: [PATCH] [IMP] uom: unique reference UoM per category Users can configure multiple references in a same category. This might cause problems during conversion and does not make sense. Since this is a "late" constraint, we define it in python to avoid conflict with existing data. We allow user to have multiple unactive reference, but force to have exactly one active. So when a new UoM category is created, user have to encode the reference unit first, and then the bigger/smaller ones. This commit also update stock tests, since they were redefining new reference UoM in the same category, and finally, this commit provides some tests for this uniqueness and custom UoM behavior. Task #1820076 --- addons/sale_mrp/tests/test_sale_mrp_flow.py | 6 ++- addons/stock/tests/common.py | 6 ++- .../tests/test_stock_landed_costs_rounding.py | 3 +- addons/uom/data/uom_data.xml | 10 ++-- addons/uom/models/uom_uom.py | 23 ++++++++- addons/uom/tests/test_uom.py | 48 +++++++++++++++++++ 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index 8c6fde71db9..2a1af0ec02b 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -37,7 +37,8 @@ class TestSaleMrpFlow(common.TransactionCase): p.route_ids.add(r) return p.save() - self.uom_kg = self.UoM.create({ + self.uom_kg = self.env['uom.uom'].search([('category_id', '=', self.categ_kgm.id), ('uom_type', '=', 'reference')], limit=1) + self.uom_kg.write({ 'name': 'Test-KG', 'category_id': self.categ_kgm.id, 'factor_inv': 1, @@ -50,7 +51,8 @@ class TestSaleMrpFlow(common.TransactionCase): 'uom_type': 'smaller', 'factor': 1000.0, 'rounding': 0.001}) - self.uom_unit = self.UoM.create({ + self.uom_unit = self.env['uom.uom'].search([('category_id', '=', self.categ_unit.id), ('uom_type', '=', 'reference')], limit=1) + self.uom_unit.write({ 'name': 'Test-Unit', 'category_id': self.categ_unit.id, 'factor': 1, diff --git a/addons/stock/tests/common.py b/addons/stock/tests/common.py index 31a7f78df1d..8c26b60e6f3 100644 --- a/addons/stock/tests/common.py +++ b/addons/stock/tests/common.py @@ -45,7 +45,8 @@ class TestStockCommon(common.TransactionCase): self.productE = self.ProductObj.create({'name': 'Product E', 'type': 'product'}) # Configure unit of measure. - self.uom_kg = self.UomObj.create({ + self.uom_kg = self.env['uom.uom'].search([('category_id', '=', self.categ_kgm), ('uom_type', '=', 'reference')], limit=1) + self.uom_kg.write({ 'name': 'Test-KG', 'category_id': self.categ_kgm, 'factor_inv': 1, @@ -71,7 +72,8 @@ class TestStockCommon(common.TransactionCase): 'factor': 100000.0, 'rounding': 0.001}) # Check Unit - self.uom_unit = self.UomObj.create({ + self.uom_unit = self.env['uom.uom'].search([('category_id', '=', self.categ_unit), ('uom_type', '=', 'reference')], limit=1) + self.uom_unit.write({ 'name': 'Test-Unit', 'category_id': self.categ_unit, 'factor': 1, diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py b/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py index 082d5069ca9..f79d285bd23 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py @@ -15,7 +15,8 @@ class TestStockLandedCostsRounding(TestStockLandedCostsCommon): self._load('stock_account', 'test', 'stock_valuation_account.xml') # Define undivisible units - product_uom_unit_round_1 = self.env['uom.uom'].create({ + product_uom_unit_round_1 = self.env.ref('uom.product_uom_unit') + product_uom_unit_round_1.write({ 'category_id': self.ref('uom.product_uom_categ_unit'), 'name': 'Undivisible Unit(s)', 'factor': 1.0, diff --git a/addons/uom/data/uom_data.xml b/addons/uom/data/uom_data.xml index 59a2c41208c..2c5cf503797 100644 --- a/addons/uom/data/uom_data.xml +++ b/addons/uom/data/uom_data.xml @@ -51,17 +51,17 @@ smaller + + Day(s) + + + Hour(s) smaller - - Day(s) - - -