diff --git a/shopfloor/actions/message.py b/shopfloor/actions/message.py index c5bcf1365a0..62969334193 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 73b4ec3fb65..2a389705041 100644 --- a/shopfloor/services/zone_picking.py +++ b/shopfloor/services/zone_picking.py @@ -940,25 +940,33 @@ 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) + elif any( + line.picking_id.picking_type_id.id not self.picking_types.ids + for line in package.planned_move_line_ids + ): + message = self.msg_store.package_different_picking_type( + package, line.picking_id.picking_type_id + ) + 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