diff --git a/stock_move_location/tests/test_move_location.py b/stock_move_location/tests/test_move_location.py index 34f036fb5..87de962f9 100644 --- a/stock_move_location/tests/test_move_location.py +++ b/stock_move_location/tests/test_move_location.py @@ -151,6 +151,77 @@ class TestMoveLocation(TestsCommon): [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 123.0], ) + def test_planned_transfer_strict(self): + product = self.env["product.product"].create( + {"name": "Test", "type": "product", "tracking": "lot"} + ) + lot = self.env["stock.lot"].create( + { + "name": "Test lot", + "product_id": product.id, + } + ) + self.set_product_amount( + product, + self.internal_loc_1, + 10.0, + ) + self.set_product_amount( + product, + self.internal_loc_1, + 10.0, + lot_id=lot, + ) + wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) + wizard.onchange_origin_location() + wizard = wizard.with_context(planned=True) + location_lines = wizard.stock_move_location_line_ids.filtered( + lambda r: r.product_id.id != product.id or r.lot_id.id != lot.id + ) + location_lines.unlink() + wizard.action_move_location() + picking = wizard.picking_id + self.assertEqual(picking.state, "assigned") + self.assertEqual( + len(wizard.stock_move_location_line_ids), len(picking.move_line_ids) + ) + location_line = wizard.stock_move_location_line_ids + wizard_lines = [ + location_line.product_id.id, + location_line.lot_id.id, + location_line.move_quantity, + ] + line = picking.move_line_ids + picking_lines = [line.product_id.id, line.lot_id.id, line.reserved_uom_qty] + self.assertEqual( + wizard_lines, + picking_lines, + "Mismatch between move location lines and move lines", + ) + self.assertEqual( + picking.move_line_ids.reserved_uom_qty, + 10.0, + ) + + # Create planned transfer for same quant + wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) + wizard.onchange_origin_location() + wizard = wizard.with_context(planned=True) + location_lines = wizard.stock_move_location_line_ids.filtered( + lambda r: r.product_id.id != product.id or r.lot_id.id != lot.id + ) + location_lines.unlink() + wizard.action_move_location() + picking = wizard.picking_id + self.assertEqual(picking.state, "assigned") + self.assertEqual( + len(wizard.stock_move_location_line_ids), len(picking.move_line_ids) + ) + self.assertEqual( + picking.move_line_ids.mapped("reserved_uom_qty"), + [0.0], + ) + def test_quant_transfer(self): """Test quants transfer.""" quants = self.product_lots.stock_quant_ids diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index 53380c3ea..ee6b50513 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -218,7 +218,7 @@ class StockMoveLocationWizard(models.TransientModel): lot_id=line.lot_id, package_id=line.package_id, owner_id=line.owner_id, - strict=False, + strict=True, ) move._update_reserved_quantity( line.move_quantity, @@ -227,7 +227,7 @@ class StockMoveLocationWizard(models.TransientModel): lot_id=line.lot_id, package_id=line.package_id, owner_id=line.owner_id, - strict=False, + strict=True, ) # Force the state to be assigned, instead of _action_assign, # to avoid discarding the selected move_location_line.