From cb93430699620745be3d3c918796f90743e41e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 14 Mar 2023 16:38:06 +0100 Subject: [PATCH] Merge multiple dimensions on package and package type Closes #12139 --- modules/stock_package/CHANGELOG | 1 + modules/stock_package/stock.py | 76 ++++++++--------- .../tests/scenario_stock_package.rst | 18 ++-- modules/stock_package/view/package_form.xml | 18 ++-- .../stock_package/view/package_type_form.xml | 18 ++-- modules/stock_package_shipping/CHANGELOG | 1 + modules/stock_package_shipping/__init__.py | 1 - modules/stock_package_shipping/stock.py | 84 +------------------ modules/stock_package_shipping/stock.xml | 6 -- .../view/package_form.xml | 13 --- .../view/package_type_form.xml | 18 ---- 11 files changed, 65 insertions(+), 189 deletions(-) delete mode 100644 modules/stock_package_shipping/view/package_type_form.xml diff --git a/modules/stock_package/CHANGELOG b/modules/stock_package/CHANGELOG index 8f8a45f9a0..f4d42e86cd 100644 --- a/modules/stock_package/CHANGELOG +++ b/modules/stock_package/CHANGELOG @@ -1,3 +1,4 @@ +* Remove packaging prefix from dimensions * Remove support for Python 3.7 * Add support for Python 3.11 diff --git a/modules/stock_package/stock.py b/modules/stock_package/stock.py index c50533a003..4dd9fc476d 100644 --- a/modules/stock_package/stock.py +++ b/modules/stock_package/stock.py @@ -80,54 +80,49 @@ class ConfigurationSequence(metaclass=PoolMeta): class MeasurementsMixin: __slots__ = () - packaging_length = fields.Float( - "Packaging Length", digits='packaging_length_uom', + length = fields.Float( + "Length", digits='length_uom', help="The length of the package.") - packaging_length_uom = fields.Many2One( - 'product.uom', "Packaging Length UOM", + length_uom = fields.Many2One( + 'product.uom', "Length UOM", domain=[('category', '=', Id('product', 'uom_cat_length'))], states={ - 'required': Bool(Eval('packaging_length')), - }, - depends=['packaging_length']) - packaging_height = fields.Float( - "Packaging Height", digits='packaging_height_uom', + 'required': Bool(Eval('length')), + }) + height = fields.Float( + "Height", digits='height_uom', help="The height of the package.") - packaging_height_uom = fields.Many2One( - 'product.uom', "Packaging Height UOM", + height_uom = fields.Many2One( + 'product.uom', "Height UOM", domain=[('category', '=', Id('product', 'uom_cat_length'))], states={ - 'required': Bool(Eval('packaging_height')), - }, - depends=['packaging_height']) - packaging_width = fields.Float( - "Packaging Width", digits='packaging_width_uom', + 'required': Bool(Eval('height')), + }) + width = fields.Float( + "Width", digits='width_uom', help="The width of the package.") - packaging_width_uom = fields.Many2One( - 'product.uom', "Packaging Width UOM", + width_uom = fields.Many2One( + 'product.uom', "Width UOM", domain=[('category', '=', Id('product', 'uom_cat_length'))], states={ - 'required': Bool(Eval('packaging_width')), - }, - depends=['packaging_width']) + 'required': Bool(Eval('width')), + }) packaging_volume = fields.Float( "Packaging Volume", digits='packaging_volume_uom', states={ 'readonly': ( - Bool(Eval('packaging_length')) - & Bool(Eval('packaging_height')) - & Bool(Eval('packaging_width'))), + Bool(Eval('length')) + & Bool(Eval('height')) + & Bool(Eval('width'))), }, - depends=['packaging_length', 'packaging_height', 'packaging_width'], help="The volume of the package.") packaging_volume_uom = fields.Many2One( 'product.uom', "Packaging Volume UOM", domain=[('category', '=', Id('product', 'uom_cat_volume'))], states={ 'required': Bool(Eval('packaging_volume')), - }, - depends=['packaging_volume']) + }) packaging_weight = fields.Float( "Packaging Weight", digits='packaging_weight_uom', @@ -141,22 +136,22 @@ class MeasurementsMixin: @fields.depends( 'packaging_volume', 'packaging_volume_uom', - 'packaging_length', 'packaging_length_uom', - 'packaging_height', 'packaging_height_uom', - 'packaging_width', 'packaging_width_uom') + 'length', 'length_uom', + 'height', 'height_uom', + 'width', 'width_uom') def on_change_with_packaging_volume(self): pool = Pool() ModelData = pool.get('ir.model.data') Uom = pool.get('product.uom') if not all([self.packaging_volume_uom, - self.packaging_length, self.packaging_length_uom, - self.packaging_height, self.packaging_height_uom, - self.packaging_width, self.packaging_width_uom]): + self.length, self.length_uom, + self.height, self.height_uom, + self.width, self.width_uom]): if all([ - self.packaging_length, - self.packaging_height, - self.packaging_width]): + self.length, + self.height, + self.width]): return return self.packaging_volume @@ -164,14 +159,11 @@ class MeasurementsMixin: cubic_meter = Uom(ModelData.get_id('product', 'uom_cubic_meter')) length = Uom.compute_qty( - self.packaging_length_uom, self.packaging_length, meter, - round=False) + self.length_uom, self.length, meter, round=False) height = Uom.compute_qty( - self.packaging_height_uom, self.packaging_height, meter, - round=False) + self.height_uom, self.height, meter, round=False) width = Uom.compute_qty( - self.packaging_width_uom, self.packaging_width, meter, - round=False) + self.width_uom, self.width, meter, round=False) return Uom.compute_qty( cubic_meter, length * height * width, self.packaging_volume_uom) diff --git a/modules/stock_package/tests/scenario_stock_package.rst b/modules/stock_package/tests/scenario_stock_package.rst index d74425e44d..75b9f54c7e 100644 --- a/modules/stock_package/tests/scenario_stock_package.rst +++ b/modules/stock_package/tests/scenario_stock_package.rst @@ -86,22 +86,22 @@ Package products:: >>> PackageType = Model.get('stock.package.type') >>> box = PackageType(name='box') - >>> box.packaging_length = 80 - >>> box.packaging_length_uom, = ProductUom.find([('name', '=', "Centimeter")]) - >>> box.packaging_width = 1 - >>> box.packaging_width_uom, = ProductUom.find([('name', '=', "Meter")]) - >>> box.packaging_height_uom = box.packaging_length_uom + >>> box.length = 80 + >>> box.length_uom, = ProductUom.find([('name', '=', "Centimeter")]) + >>> box.width = 1 + >>> box.width_uom, = ProductUom.find([('name', '=', "Meter")]) + >>> box.height_uom = box.length_uom >>> box.packaging_volume >>> box.packaging_volume_uom, = ProductUom.find([('name', '=', "Cubic meter")]) >>> box.save() >>> package1 = shipment_out.packages.new(type=box) - >>> package1.packaging_length + >>> package1.length 80.0 - >>> package1.packaging_height = 50 + >>> package1.height = 50 >>> package1.packaging_volume 0.4 >>> package_child = package1.children.new(shipment=shipment_out, type=box) - >>> package_child.packaging_height = 100 + >>> package_child.height = 100 >>> moves = package_child.moves.find() >>> len(moves) 2 @@ -112,7 +112,7 @@ Package products:: ... PackageValidationError: ... - >>> package1.packaging_height = 120 + >>> package1.height = 120 >>> package1.packaging_volume 0.96 diff --git a/modules/stock_package/view/package_form.xml b/modules/stock_package/view/package_form.xml index f149fc19d9..9bf54e9df4 100644 --- a/modules/stock_package/view/package_form.xml +++ b/modules/stock_package/view/package_form.xml @@ -20,17 +20,17 @@ this repository contains the full copyright notices and license terms. --> -