From 9cc01683ff8fe77533d687a56e1ca74f3097be1f Mon Sep 17 00:00:00 2001 From: Michael Tietz Date: Thu, 10 Aug 2023 22:20:20 +0200 Subject: [PATCH] [IMP] shopfloor: zone picking is package not valid - a package is now also not valid if it already contains move lines from an other picking type --- shopfloor/actions/message.py | 8 ++++ shopfloor/services/zone_picking.py | 37 ++++++++++++------- .../test_zone_picking_set_line_destination.py | 35 ++++++++++++++++++ 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/shopfloor/actions/message.py b/shopfloor/actions/message.py index c5bcf1365a..6296933419 100644 --- a/shopfloor/actions/message.py +++ b/shopfloor/actions/message.py @@ -126,6 +126,14 @@ def package_already_used(self, package): "body": _("Package {} is already used.").format(package.name), } + def package_different_picking_type(self, package, picking_type): + return { + "message_type": "warning", + "body": _( + "Package {} contains already lines from a different operation type {}" + ).format(package.name, picking_type.name), + } + def dest_package_required(self): return { "message_type": "warning", diff --git a/shopfloor/services/zone_picking.py b/shopfloor/services/zone_picking.py index 73b4ec3fb6..e010bd2c94 100644 --- a/shopfloor/services/zone_picking.py +++ b/shopfloor/services/zone_picking.py @@ -940,25 +940,34 @@ def _move_line_full_qty(self, move_line, qty): move_line.product_uom_qty - qty, precision_rounding=rounding ) - def _set_destination_package(self, move_line, quantity, package): - package_changed = False - response = None + def _is_package_not_valid(self, package): + message = False # A valid package is: # * an empty package # * not used as destination for another move line + # * not contains move lines with different operation type if not self._is_package_empty(package): + message = self.msg_store.package_not_empty(package) + elif package.planned_move_line_ids: + if not self.work.menu.multiple_move_single_pack: + message = self.msg_store.package_already_used(package) + else: + for line in package.planned_move_line_ids: + if line.picking_id.picking_type_id.id in self.picking_types.ids: + continue + message = self.msg_store.package_different_picking_type( + package, line.picking_id.picking_type_id + ) + break + return message + + def _set_destination_package(self, move_line, quantity, package): + package_changed = False + response = None + package_invalid_message = self._is_package_not_valid(package) + if package_invalid_message: response = self._response_for_set_line_destination( - move_line, - message=self.msg_store.package_not_empty(package), - qty_done=quantity, - ) - return (package_changed, response) - multiple_move_allowed = self.work.menu.multiple_move_single_pack - if package.planned_move_line_ids and not multiple_move_allowed: - response = self._response_for_set_line_destination( - move_line, - message=self.msg_store.package_already_used(package), - qty_done=quantity, + move_line, message=package_invalid_message, qty_done=quantity ) return (package_changed, response) # the quantity done is set to the passed quantity diff --git a/shopfloor/tests/test_zone_picking_set_line_destination.py b/shopfloor/tests/test_zone_picking_set_line_destination.py index b1a8fd3db8..27916c3168 100644 --- a/shopfloor/tests/test_zone_picking_set_line_destination.py +++ b/shopfloor/tests/test_zone_picking_set_line_destination.py @@ -580,6 +580,41 @@ def test_set_same_destination_package_multiple_moves(self): message=self.service.msg_store.confirm_pack_moved(), ) + def test_set_same_destination_package_different_picking_type(self): + self.menu.sudo().write({"multiple_move_single_pack": True}) + picking_type1 = self.picking1.picking_type_id + self._update_qty_in_location( + picking_type1.default_location_src_id, self.product_a, 100 + ) + picking_type = picking_type1.sudo().copy( + {"name": "test", "shopfloor_menu_ids": False} + ) + picking = self._create_picking( + picking_type=picking_type, lines=[(self.product_a, 10)] + ) + self.assertEqual(picking.picking_type_id, picking_type) + picking.action_assign() + move_line = picking.move_line_ids + move_line.result_package_id = self.free_package.id + self.assertEqual(self.free_package.planned_move_line_ids, move_line) + response = self.service.dispatch( + "set_destination", + params={ + "move_line_id": move_line.id, + "barcode": self.free_package.name, + "quantity": move_line.product_uom_qty, + "confirmation": False, + }, + ) + self.assertEqual( + response["message"], + { + "body": "Package FREE_PACKAGE contains already lines" + " from a different operation type test", + "message_type": "warning", + }, + ) + def test_set_destination_location_zero_quantity(self): """Scanned barcode is the destination location.