diff --git a/shopfloor/services/cluster_picking.py b/shopfloor/services/cluster_picking.py index 881b56931e..e40d981491 100644 --- a/shopfloor/services/cluster_picking.py +++ b/shopfloor/services/cluster_picking.py @@ -601,7 +601,12 @@ def scan_destination_pack(self, picking_batch_id, move_line_id, barcode, quantit # contained less items than expected) remaining = move_line.product_uom_qty - quantity new_line = move_line.copy({"product_uom_qty": remaining, "qty_done": 0}) - move_line.product_uom_qty = quantity + # if we didn't bypass reservation update, the quant reservation + # would be reduced as much as the deduced quantity, which is wrong + # as we only moved the quantity to a new move line + move_line.with_context( + bypass_reservation_update=True + ).product_uom_qty = quantity search = self.actions_for("search") bin_package = search.package_from_scan(barcode) diff --git a/shopfloor/tests/test_cluster_picking_scan.py b/shopfloor/tests/test_cluster_picking_scan.py index b67471d560..11909cccf0 100644 --- a/shopfloor/tests/test_cluster_picking_scan.py +++ b/shopfloor/tests/test_cluster_picking_scan.py @@ -467,6 +467,15 @@ def test_scan_destination_pack_quantity_more(self): def test_scan_destination_pack_quantity_less(self): """Pick less units than expected""" line = self.one_line_picking.move_line_ids + quant = self.env["stock.quant"].search( + [ + ("location_id", "=", line.location_id.id), + ("product_id", "=", line.product_id.id), + ] + ) + quant.ensure_one() + self.assertRecordValues(quant, [{"quantity": 40.0, "reserved_quantity": 20.0}]) + # when we pick less quantity than expected, the line is split # and the user is proposed to pick the next line for the remaining # quantity @@ -479,16 +488,7 @@ def test_scan_destination_pack_quantity_less(self): "quantity": line.product_uom_qty - 3, }, ) - - self.assertRecordValues( - line, - [{"qty_done": 7, "result_package_id": self.bin1.id, "product_uom_qty": 7}], - ) new_line = self.one_line_picking.move_line_ids - line - self.assertRecordValues( - new_line, - [{"qty_done": 0, "result_package_id": False, "product_uom_qty": 3}], - ) self.assert_response( response, @@ -502,6 +502,17 @@ def test_scan_destination_pack_quantity_less(self): }, ) + self.assertRecordValues( + line, + [{"qty_done": 7, "result_package_id": self.bin1.id, "product_uom_qty": 7}], + ) + self.assertRecordValues( + new_line, + [{"qty_done": 0, "result_package_id": False, "product_uom_qty": 3}], + ) + # the reserved quantity on the quant must stay the same + self.assertRecordValues(quant, [{"quantity": 40.0, "reserved_quantity": 20.0}]) + def test_scan_destination_pack_zero_check(self): """Location will be emptied, have to go to zero check""" line = self.one_line_picking.move_line_ids