diff --git a/delivery_carrier_package_measure_required/__manifest__.py b/delivery_carrier_package_measure_required/__manifest__.py index fa9a340b1e..d6c81469b2 100644 --- a/delivery_carrier_package_measure_required/__manifest__.py +++ b/delivery_carrier_package_measure_required/__manifest__.py @@ -4,7 +4,7 @@ Allow the configuration of which package measurements are required on a delivery carrier basis. """, - "version": "14.0.1.0.2", + "version": "16.0.1.0.0", "license": "AGPL-3", "author": "Camptocamp, Odoo Community Association (OCA)", "website": "https://github.com/OCA/delivery-carrier", @@ -15,7 +15,7 @@ "stock_quant_package_dimension", ], "data": [ - "views/product_packaging.xml", + "views/stock_package_type_views.xml", "wizard/choose_delivery_package.xml", ], "installable": True, diff --git a/delivery_carrier_package_measure_required/models/__init__.py b/delivery_carrier_package_measure_required/models/__init__.py index cb7177dedf..2f66e4bb1d 100644 --- a/delivery_carrier_package_measure_required/models/__init__.py +++ b/delivery_carrier_package_measure_required/models/__init__.py @@ -1,3 +1,3 @@ -from . import product_packaging +from . import stock_package_type from . import stock_picking from . import stock_quant_package diff --git a/delivery_carrier_package_measure_required/models/product_packaging.py b/delivery_carrier_package_measure_required/models/stock_package_type.py similarity index 84% rename from delivery_carrier_package_measure_required/models/product_packaging.py rename to delivery_carrier_package_measure_required/models/stock_package_type.py index 127d8bd8b5..a63d7afdc7 100644 --- a/delivery_carrier_package_measure_required/models/product_packaging.py +++ b/delivery_carrier_package_measure_required/models/stock_package_type.py @@ -4,8 +4,8 @@ from odoo import fields, models -class ProductPackaging(models.Model): - _inherit = "product.packaging" +class StockPackageType(models.Model): + _inherit = "stock.package.type" package_height_required = fields.Boolean(string="Height required") package_length_required = fields.Boolean(string="Length required") diff --git a/delivery_carrier_package_measure_required/models/stock_picking.py b/delivery_carrier_package_measure_required/models/stock_picking.py index 0654c14b43..77489f5758 100644 --- a/delivery_carrier_package_measure_required/models/stock_picking.py +++ b/delivery_carrier_package_measure_required/models/stock_picking.py @@ -19,3 +19,21 @@ def _check_required_package_measurement(self): def button_validate(self): self._check_required_package_measurement() return super().button_validate() + + def _put_in_pack(self, move_line_ids, create_package_level=True): + res = super()._put_in_pack( + move_line_ids, create_package_level=create_package_level + ) + package_length = self._context.get("choose_delivery_package_length", 0) + package_width = self._context.get("choose_delivery_package_width", 0) + package_height = self._context.get("choose_delivery_package_height", 0) + + res.write( + { + "pack_length": package_length, + "width": package_width, + "height": package_height, + } + ) + + return res diff --git a/delivery_carrier_package_measure_required/models/stock_quant_package.py b/delivery_carrier_package_measure_required/models/stock_quant_package.py index eb966891c6..c3ebdb3582 100644 --- a/delivery_carrier_package_measure_required/models/stock_quant_package.py +++ b/delivery_carrier_package_measure_required/models/stock_quant_package.py @@ -8,10 +8,10 @@ class StockQuantPackage(models.Model): _inherit = "stock.quant.package" - length_required = fields.Boolean(related="packaging_id.package_length_required") - width_required = fields.Boolean(related="packaging_id.package_width_required") - height_required = fields.Boolean(related="packaging_id.package_height_required") - weight_required = fields.Boolean(related="packaging_id.package_weight_required") + length_required = fields.Boolean(related="package_type_id.package_length_required") + width_required = fields.Boolean(related="package_type_id.package_width_required") + height_required = fields.Boolean(related="package_type_id.package_height_required") + weight_required = fields.Boolean(related="package_type_id.package_weight_required") # The boolean field use to check if a dimension is required are intentionally left out. # To not raise error when changing packaging configuration. diff --git a/delivery_carrier_package_measure_required/readme/DESCRIPTION.rst b/delivery_carrier_package_measure_required/readme/DESCRIPTION.rst index 51666e8352..e2db95e6c3 100644 --- a/delivery_carrier_package_measure_required/readme/DESCRIPTION.rst +++ b/delivery_carrier_package_measure_required/readme/DESCRIPTION.rst @@ -2,7 +2,7 @@ This module adds the possibility to flag some measurements on package to be requ It depends on the `stock_quant_package_dimension` which adds more dimensions on packages. -The required measurement can be flagged on the product packaging. +The required measurement can be flagged on the package type. Then the dimension can be set on the wizard displayed by the Put In Pack button. diff --git a/delivery_carrier_package_measure_required/tests/test_delivery_carrier_package_measure_require.py b/delivery_carrier_package_measure_required/tests/test_delivery_carrier_package_measure_require.py index 0057beb5e5..c1305a5f90 100644 --- a/delivery_carrier_package_measure_required/tests/test_delivery_carrier_package_measure_require.py +++ b/delivery_carrier_package_measure_required/tests/test_delivery_carrier_package_measure_require.py @@ -12,7 +12,7 @@ class TestDeliveryCarrierPackageMeasureRequire(TestPackingCommon): def setUpClass(cls): super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - cls.normal_carrier = cls.env.ref("delivery.normal_delivery_carrier") + cls.normal_carrier = cls.env.ref("delivery.free_delivery_carrier") cls.uom_kg = cls.env.ref("uom.product_uom_kgm") cls.product_aw = cls.env["product.product"].create( { @@ -23,7 +23,7 @@ def setUpClass(cls): "uom_po_id": cls.uom_kg.id, } ) - cls.packaging = cls.env["product.packaging"].create( + cls.packaging = cls.env["stock.package.type"].create( {"name": "Test Delivery Packaging"} ) cls.env["stock.quant"]._update_available_quantity( @@ -38,12 +38,13 @@ def setUpClass(cls): "carrier_id": cls.normal_carrier.id, } ) - cls.env["stock.move.line"].create( + cls.env["stock.move"].create( { + "name": cls.product_aw.name, "product_id": cls.product_aw.id, - "product_uom_id": cls.uom_kg.id, + "product_uom_qty": 5, + "product_uom": cls.uom_kg.id, "picking_id": cls.pick.id, - "qty_done": 5, "location_id": cls.stock_location.id, "location_dest_id": cls.customer_location.id, } @@ -58,7 +59,7 @@ def setUpClass(cls): ) pack_wiz.action_put_in_pack() cls.package = cls.pick.move_line_ids.mapped("result_package_id") - cls.package.packaging_id = cls.packaging + cls.package.package_type_id = cls.packaging def test_force_check_required_measurement(self): self.packaging.package_length_required = True diff --git a/delivery_carrier_package_measure_required/views/product_packaging.xml b/delivery_carrier_package_measure_required/views/product_packaging.xml deleted file mode 100644 index 12dbe65106..0000000000 --- a/delivery_carrier_package_measure_required/views/product_packaging.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - product.packaging.form.delivery - product.packaging - - - - - - - - - - - - - diff --git a/delivery_carrier_package_measure_required/views/stock_package_type_views.xml b/delivery_carrier_package_measure_required/views/stock_package_type_views.xml new file mode 100644 index 0000000000..0431ecd9e9 --- /dev/null +++ b/delivery_carrier_package_measure_required/views/stock_package_type_views.xml @@ -0,0 +1,21 @@ + + + + stock.package.type.form.delivery + stock.package.type + + + + + + + + + + + + + diff --git a/delivery_carrier_package_measure_required/wizard/choose_delivery_package.py b/delivery_carrier_package_measure_required/wizard/choose_delivery_package.py index 5f57f828e2..0ac6439739 100644 --- a/delivery_carrier_package_measure_required/wizard/choose_delivery_package.py +++ b/delivery_carrier_package_measure_required/wizard/choose_delivery_package.py @@ -1,35 +1,56 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from odoo import fields, models +from odoo import api, fields, models class ChooseDeliveryPackage(models.TransientModel): _inherit = "choose.delivery.package" - pick_name = fields.Char(related="picking_id.name") + @api.depends("delivery_package_type_id") + def _compute_dimension_uom_name(self): + length_uom_id = self.env[ + "product.template" + ]._get_length_uom_id_from_ir_config_parameter() + for package in self: + package.dimension_uom_name = length_uom_id.name - def _default_dimension_uom_id(self): - val = self.env["product.template"]._get_length_uom_id_from_ir_config_parameter() - return val + @api.depends("delivery_package_type_id") + def _compute_dimension(self): + for package in self: + package.package_length = ( + package.delivery_package_type_id.packaging_length or 0 + ) + package.package_width = package.delivery_package_type_id.width or 0 + package.package_height = package.delivery_package_type_id.height or 0 - package_height = fields.Integer() - package_length = fields.Integer() - package_width = fields.Integer() - dimension_uom_id = fields.Many2one( - "uom.uom", - default=lambda self: self._default_dimension_uom_id(), + package_length = fields.Integer( + compute="_compute_dimension", store=True, readonly=False ) - dimension_uom_name = fields.Char(related="dimension_uom_id.name") + package_width = fields.Integer( + compute="_compute_dimension", store=True, readonly=False + ) + package_height = fields.Integer( + compute="_compute_dimension", store=True, readonly=False + ) + dimension_uom_name = fields.Char(compute="_compute_dimension_uom_name") package_height_required = fields.Boolean( - related="delivery_packaging_id.package_height_required" + related="delivery_package_type_id.package_height_required" ) package_length_required = fields.Boolean( - related="delivery_packaging_id.package_length_required" - ) - package_weight_required = fields.Boolean( - related="delivery_packaging_id.package_weight_required" + related="delivery_package_type_id.package_length_required" ) package_width_required = fields.Boolean( - related="delivery_packaging_id.package_width_required" + related="delivery_package_type_id.package_width_required" ) + package_weight_required = fields.Boolean( + related="delivery_package_type_id.package_weight_required" + ) + + def action_put_in_pack(self): + self = self.with_context( + choose_delivery_package_length=self.package_length, + choose_delivery_package_width=self.package_width, + choose_delivery_package_height=self.package_height, + ) + return super().action_put_in_pack() diff --git a/delivery_carrier_package_measure_required/wizard/choose_delivery_package.xml b/delivery_carrier_package_measure_required/wizard/choose_delivery_package.xml index 86b74b5f74..d31f38ef1d 100644 --- a/delivery_carrier_package_measure_required/wizard/choose_delivery_package.xml +++ b/delivery_carrier_package_measure_required/wizard/choose_delivery_package.xml @@ -13,11 +13,11 @@