Skip to content

Commit

Permalink
[MIG] delivery_carrier_package_measure_required: Migration to 16.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoBM committed Oct 3, 2023
1 parent e1358f2 commit 2094b7e
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 57 deletions.
4 changes: 2 additions & 2 deletions delivery_carrier_package_measure_required/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import product_packaging
from . import stock_package_type
from . import stock_picking
from . import stock_quant_package
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions delivery_carrier_package_measure_required/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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(
Expand Down Expand Up @@ -58,7 +58,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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_stock_package_type_form_delivery_inherit" model="ir.ui.view">
<field name="name">stock.package.type.form.delivery</field>
<field name="model">stock.package.type</field>
<field name="inherit_id" ref="delivery.stock_package_type_form_delivery" />
<field name="arch" type="xml">
<xpath expr="//group[@name='delivery']" position="inside">
<group
name="carrier_required_mesaurement"
string="Carrier Required Measurements"
>
<field name="package_length_required" />
<field name="package_width_required" />
<field name="package_height_required" />
<field name="package_weight_required" />
</group>
</xpath>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -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[

Check warning on line 12 in delivery_carrier_package_measure_required/wizard/choose_delivery_package.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_package_measure_required/wizard/choose_delivery_package.py#L12

Added line #L12 was not covered by tests
"product.template"
]._get_length_uom_id_from_ir_config_parameter()
for package in self:
package.dimension_uom_name = length_uom_id.name

Check warning on line 16 in delivery_carrier_package_measure_required/wizard/choose_delivery_package.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_package_measure_required/wizard/choose_delivery_package.py#L16

Added line #L16 was not covered by tests

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()
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
<field name="package_width_required" invisible="1" />
<label
for="package_length"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_length_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_length_required', '=', False)]}"
/>
<div
class="o_row"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_length_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_length_required', '=', False)]}"
name="package_length"
>
<field name="package_length" />
<field name="dimension_uom_name" />
</div>
<label
for="package_width"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_width_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_width_required', '=', False)]}"
/>
<div
class="o_row"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_width_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_width_required', '=', False)]}"
name="package_width"
>
<field name="package_width" />
<field name="dimension_uom_name" />
</div>
<label
for="package_height"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_height_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_height_required', '=', False)]}"
/>
<div
class="o_row"
attrs="{'invisible': ['|', ('delivery_packaging_id', '=', False), ('package_height_required', '=', False)]}"
attrs="{'invisible': ['|', ('delivery_package_type_id', '=', False), ('package_height_required', '=', False)]}"
name="package_height"
>
<field name="package_height" />
Expand Down

0 comments on commit 2094b7e

Please sign in to comment.