[MIG] stock_packaging_calculator_packaging_type: Migration to 16.0

This commit is contained in:
mle
2023-10-06 12:44:06 +02:00
parent cd243d8c5d
commit 9a5bbf0e78
4 changed files with 22 additions and 18 deletions

View File

@@ -3,7 +3,7 @@
{
"name": "Stock packaging calculator packaging type",
"summary": "Glue module for packaging type",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
@@ -12,5 +12,5 @@
"application": False,
"installable": True,
"auto_install": True,
"depends": ["stock_packaging_calculator", "product_packaging_type"],
"depends": ["stock_packaging_calculator", "product_packaging_level"],
}

View File

@@ -8,7 +8,7 @@ class Product(models.Model):
_inherit = "product.product"
def _packaging_name_getter(self, packaging):
return packaging.packaging_type_id.name
return packaging.packaging_level_id.name
def _qty_by_packaging_as_str(self, packaging, qty):
# By default use packaging type code
@@ -17,9 +17,9 @@ class Product(models.Model):
)
compact_mode = self.env.context.get("qty_by_packaging_type_compact", True)
sep = "" if compact_mode else " "
# Override to use packaging type code
if packaging and packaging.packaging_type_id:
name = packaging.packaging_type_id[qty_by_packaging_type_fname]
# Override to use packaging level code
if packaging and packaging.packaging_level_id:
name = packaging.packaging_level_id[qty_by_packaging_type_fname]
return f"{qty}{sep}{name}"
else:
return super()._qty_by_packaging_as_str(packaging, qty)

View File

@@ -19,4 +19,4 @@ class ProductQtyByPackagingMixin(models.AbstractModel):
"qty_by_packaging_type_compact",
)
def _compute_product_qty_by_packaging_display(self):
super()._compute_product_qty_by_packaging_display()
return super()._compute_product_qty_by_packaging_display()

View File

@@ -8,32 +8,36 @@ class TestCalc(TestCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.type_retail_box = cls.env["product.packaging.type"].create(
cls.level_retail_box = cls.env["product.packaging.level"].create(
{"name": "Retail Box", "code": "PACK", "sequence": 3}
)
cls.type_transport_box = cls.env["product.packaging.type"].create(
cls.level_transport_box = cls.env["product.packaging.level"].create(
{"name": "Transport Box", "code": "CASE", "sequence": 4}
)
cls.type_pallet = cls.env["product.packaging.type"].create(
cls.level_pallet = cls.env["product.packaging.level"].create(
{"name": "Pallet", "code": "PALLET", "sequence": 5}
)
cls.pkg_box.packaging_type_id = cls.type_retail_box
cls.pkg_big_box.packaging_type_id = cls.type_transport_box
cls.pkg_pallet.packaging_type_id = cls.type_pallet
cls.pkg_box.packaging_level_id = cls.level_retail_box
cls.pkg_big_box.packaging_level_id = cls.level_transport_box
cls.pkg_pallet.packaging_level_id = cls.level_pallet
def test_calc_1(self):
expected = [
make_pkg_values(self.pkg_pallet, qty=1, name=self.type_pallet.name),
make_pkg_values(self.pkg_big_box, qty=3, name=self.type_transport_box.name),
make_pkg_values(self.pkg_box, qty=1, name=self.type_retail_box.name),
make_pkg_values(self.pkg_pallet, qty=1, name=self.level_pallet.name),
make_pkg_values(
self.pkg_big_box, qty=3, name=self.level_transport_box.name
),
make_pkg_values(self.pkg_box, qty=1, name=self.level_retail_box.name),
make_pkg_values(self.uom_unit, qty=5),
]
self.assertEqual(self.product_a.product_qty_by_packaging(2655), expected)
def test_calc_2(self):
expected = [
make_pkg_values(self.pkg_big_box, qty=1, name=self.type_transport_box.name),
make_pkg_values(self.pkg_box, qty=3, name=self.type_retail_box.name),
make_pkg_values(
self.pkg_big_box, qty=1, name=self.level_transport_box.name
),
make_pkg_values(self.pkg_box, qty=3, name=self.level_retail_box.name),
]
self.assertEqual(self.product_a.product_qty_by_packaging(350), expected)