Skip to content

Commit

Permalink
[FIX] stock_storage_type: Fix the behaviour to get the package type a…
Browse files Browse the repository at this point in the history
…t auto assignation from product
  • Loading branch information
rousseldenis committed Apr 28, 2023
1 parent 1bcd098 commit 75b2630
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion stock_storage_type/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _sync_package_type_from_packaging(self):

def _sync_package_type_from_single_product(self):
for package in self:
if package.packaging_id:
if package.package_type_id:
# Do not set package type for delivery packages
# to not trigger constraint like height requirement
# (we are delivering them, not storing them)
Expand Down
53 changes: 35 additions & 18 deletions stock_storage_type/tests/test_auto_assign_storage_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def setUpClass(cls):
cls.product_packaging = cls.product_lot_pallets_product_packaging
cls.package_storage_type = cls.product_packaging.package_type_id

# Create a new package type for auto assignation
vals = {
"name": "Auto Assigned Package Type",
}
cls.auto_assigned_package_type = cls.env["stock.package.type"].create(vals)

def test_auto_assign_package_storage_type_without_packaging_id(self):
"""Packages without `packaging_id` are internal packages and they
are intended to be stored in the warehouse.
Expand All @@ -20,22 +26,33 @@ def test_auto_assign_package_storage_type_without_packaging_id(self):
)
self.assertEqual(package.package_type_id, self.package_storage_type)

def test_auto_assign_package_storage_type_with_packaging_id(self):
"""Packages with `packaging_id` are delivery packages and they are not
intended to be stored in the warehouse.
On such packages storage type is not set.
def test_auto_assign_packaging(self):
"""
Test the auto assignation for package type from
the default package type on the product
- Set the default package type on the product
- Create a move and validate it
- The package type should be set on product
"""
# TODO: This should not be the case now as :
# There is a field to check if the quant.package is related to a delivery carrier
# package_carrier_type: none by default
# Set a delivery packaging (which is a stock.package.type)

# packaging = self.env["stock.package.type"].create({"name": "TEST"})
# package = self.env["stock.quant.package"].create(
# {
# "name": "TEST",
# "product_packaging_id": self.product_packaging.id,
# "package_type_id": packaging.id,
# }
# )
# self.assertFalse(package.package_type_id)

# Set a default package on the product
self.product.package_type_id = self.auto_assigned_package_type

confirmed_move = self._create_single_move(self.product)
confirmed_move.location_dest_id = self.pallets_bin_1_location
confirmed_move._assign_picking()
self._update_qty_in_location(
confirmed_move.location_id,
confirmed_move.product_id,
confirmed_move.product_qty,
)
confirmed_move._action_assign()
picking = confirmed_move.picking_id
picking.action_confirm()
picking.move_line_ids.qty_done = 10.0
first_package = picking.action_put_in_pack()

picking.button_validate()

self.assertEqual(self.auto_assigned_package_type, first_package.package_type_id)

0 comments on commit 75b2630

Please sign in to comment.