From d3273bf3c66bf5874234b8181e5a2fa675745f0e Mon Sep 17 00:00:00 2001 From: Lindsay Date: Thu, 14 Apr 2022 10:22:32 +0200 Subject: [PATCH] [FIX] Prevent the user to pick a quantity = 0 when scanning the destination pack --- shopfloor/actions/message.py | 6 +++++ shopfloor/services/cluster_picking.py | 5 ++++ .../test_cluster_picking_scan_destination.py | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/shopfloor/actions/message.py b/shopfloor/actions/message.py index 0d6793c4964..0e3f77c6b4e 100644 --- a/shopfloor/actions/message.py +++ b/shopfloor/actions/message.py @@ -575,3 +575,9 @@ def picking_without_carrier_cannot_pack(self, picking): "The system couldn't pack goods automatically." ).format(picking), } + + def qty_must_be_greater_than_zero(self): + return { + "message_type": "error", + "body": _(u"Quantity must be greater than zero."), + } diff --git a/shopfloor/services/cluster_picking.py b/shopfloor/services/cluster_picking.py index 5c9897af408..ad2ae341838 100644 --- a/shopfloor/services/cluster_picking.py +++ b/shopfloor/services/cluster_picking.py @@ -600,6 +600,11 @@ def scan_destination_pack(self, picking_batch_id, move_line_id, barcode, quantit move_line, message=self.msg_store.bin_not_found_for_barcode(barcode) ) + if quantity <= 0: + return self._response_for_scan_destination( + move_line, message=self.msg_store.qty_must_be_greater_than_zero() + ) + # the scanned package can contain only move lines of the same picking if bin_package.quant_ids or any( ml.picking_id != move_line.picking_id diff --git a/shopfloor/tests/test_cluster_picking_scan_destination.py b/shopfloor/tests/test_cluster_picking_scan_destination.py index 4b7ab393055..d2d98a7575d 100644 --- a/shopfloor/tests/test_cluster_picking_scan_destination.py +++ b/shopfloor/tests/test_cluster_picking_scan_destination.py @@ -334,3 +334,26 @@ def test_scan_destination_pack_zero_check_disabled(self): ), }, ) + + def test_scan_destination_pack_zero_quantity(self): + """Try to enter 0 as quantity picked : should not be possible""" + line = self.batch.move_line_ids[0] + response = self.service.dispatch( + "scan_destination_pack", + params={ + "picking_batch_id": self.batch.id, + "move_line_id": line.id, + "barcode": self.bin1.name, + "quantity": 0, + }, + ) + + self.assert_response( + response, + next_state="scan_destination", + data=self.self._line_data(line), + message={ + "message_type": "error", + "body": "Quantity must be greater than zero.", + }, + )