Skip to content

Commit 21f31bf

Browse files
committed
shopfloor cluster_picking: scan dest update qty: use handlers
1 parent 714db7f commit 21f31bf

File tree

1 file changed

+57
-35
lines changed

1 file changed

+57
-35
lines changed

shopfloor/services/cluster_picking.py

+57-35
Original file line numberDiff line numberDiff line change
@@ -686,43 +686,65 @@ def _scan_line_by_location(self, picking, move_line, location):
686686

687687
def _set_destination_pack_update_quantity(self, move_line, quantity, barcode):
688688
"""Handle the done quantity increment on set_destination end point."""
689-
response = None
690689
if not self.work.menu.no_prefill_qty:
691-
return response
690+
return None
691+
handlers = {
692+
"product": self._set_destination_update_quantity__by_product,
693+
"packaging": self._set_destination_update_quantity__by_packaging,
694+
"lot": self._set_destination_update_quantity__by_lot,
695+
"none": self._set_destination_update_quantity__fallback,
696+
}
697+
search_result = self._set_destination_pack_update_quantity__find(
698+
barcode, handlers.keys()
699+
)
700+
handler = handlers.get(
701+
search_result.type, self._set_destination_update_quantity__fallback
702+
)
703+
return handler(move_line, search_result.record, quantity)
704+
705+
def _set_destination_pack_update_quantity__find(self, barcode, search_types):
692706
search = self._actions_for("search")
693-
# Handle barcode of product or packaging
694-
product = search.product_from_scan(barcode)
695-
packaging = self.env["product.packaging"].browse()
696-
if not product:
697-
packaging = search.packaging_from_scan(barcode)
698-
product = packaging.product_id
699-
if product:
700-
if move_line.product_id == product:
701-
quantity += packaging.qty or 1.0
702-
response = self._response_for_scan_destination(
703-
move_line, qty_done=quantity
704-
)
705-
return response
706-
return self._response_for_scan_destination(
707-
move_line,
708-
message=self.msg_store.wrong_record(product),
709-
qty_done=quantity,
710-
)
711-
# Handle barcode of a lot
712-
lot = search.lot_from_scan(barcode)
713-
if lot:
714-
if move_line.lot_id == lot:
715-
quantity += 1.0
716-
response = self._response_for_scan_destination(
717-
move_line, qty_done=quantity
718-
)
719-
return response
720-
return self._response_for_scan_destination(
721-
move_line,
722-
message=self.msg_store.wrong_record(lot),
723-
qty_done=quantity,
724-
)
725-
return response
707+
return search.find(barcode, types=search_types)
708+
709+
def _set_destination_update_quantity__by_product(
710+
self, move_line, product, quantity
711+
):
712+
if move_line.product_id == product:
713+
quantity += 1.0
714+
return self._response_for_scan_destination(move_line, qty_done=quantity)
715+
return self._response_for_scan_destination(
716+
move_line,
717+
message=self.msg_store.wrong_record(product),
718+
qty_done=quantity,
719+
)
720+
721+
def _set_destination_update_quantity__by_packaging(
722+
self, move_line, packaging, quantity
723+
):
724+
product = packaging.product_id
725+
if move_line.product_id == product:
726+
quantity += packaging.qty
727+
return self._response_for_scan_destination(move_line, qty_done=quantity)
728+
return self._response_for_scan_destination(
729+
move_line,
730+
message=self.msg_store.wrong_record(product),
731+
qty_done=quantity,
732+
)
733+
734+
def _set_destination_update_quantity__by_lot(self, move_line, lot, quantity):
735+
if move_line.lot_id == lot:
736+
quantity += 1.0
737+
return self._response_for_scan_destination(move_line, qty_done=quantity)
738+
return self._response_for_scan_destination(
739+
move_line,
740+
message=self.msg_store.wrong_record(lot),
741+
qty_done=quantity,
742+
)
743+
744+
def _set_destination_update_quantity__fallback(
745+
self, move_line, empty_rec, quantity
746+
):
747+
return None
726748

727749
def scan_destination_pack(self, picking_batch_id, move_line_id, barcode, quantity):
728750
"""Scan the destination package (bin) for a move line

0 commit comments

Comments
 (0)