Skip to content

Commit b1ed091

Browse files
[REF] shopfloor_reception: use generic "find" inside "scan_document"
The `scan_document` processing step has been refactored to utilize the `find()` method from the shopfloor search action component. Previously, the logic manually iterated over the handlers and called the internal `_find_record_by_type` method directly, bypassing the broader search pipeline. By shifting this responsibility to the base `find` method, any standardized barcode preprocessing, custom resolution logic, or GS1-128 parsing injected into the search action component is now fully honored during reception. Furthermore, this provides downstream extending modules with a unified, singular hook point to alter or enrich barcode matching behaviors globally across the app.
1 parent b7b4950 commit b1ed091

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

shopfloor_reception/services/reception.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,11 +1036,19 @@ def start(self):
10361036
return self._response_for_select_document()
10371037

10381038
def _scan_document__get_handlers_by_type(self):
1039+
# CRITICAL ORDERING FOR THE `search.find()` PIPELINE:
1040+
# "origin_move" must come BEFORE "picking".
1041+
#
1042+
# Why? If a partial delivery occurred, a completed move and an active
1043+
# backorder picking will share the same Source Document name (e.g., SO001).
1044+
# Because `search.find()` loops through this dictionary in order, placing
1045+
# "origin_move" first ensures we trigger a return for the completed delivery
1046+
# instead of accidentally opening the pending backorder picking.
10391047
handlers_by_type = {
1048+
"origin_move": self._scan_document__by_origin_move,
10401049
"picking": self._scan_document__by_picking,
10411050
"packaging": self._scan_document__by_packaging,
10421051
"lot": self._scan_document__by_lot,
1043-
"origin_move": self._scan_document__by_origin_move,
10441052
}
10451053
# only add the handler if scan_location_or_pack_first is disabled
10461054
if not self.work.menu.scan_location_or_pack_first:
@@ -1073,17 +1081,22 @@ def scan_document(self, barcode):
10731081
single correspondance. Not tracked product
10741082
"""
10751083
handlers_by_type = self._scan_document__get_handlers_by_type()
1084+
1085+
if not handlers_by_type:
1086+
return self._scan_document__fallback()
1087+
10761088
search = self._actions_for("search")
10771089
find_kw = self._scan_document__get_find_kw()
1078-
for handler_type, handler in handlers_by_type.items():
1079-
record = search._find_record_by_type(
1080-
barcode, handler_type, handler_kw=find_kw
1081-
)
1082-
if not record:
1083-
continue
1084-
res = handler(record, barcode)
1085-
if res:
1086-
return res
1090+
1091+
result = search.find(barcode, types=handlers_by_type.keys(), handler_kw=find_kw)
1092+
1093+
if result and result.type != "none" and (recordset := result.record):
1094+
handler = handlers_by_type.get(result.type)
1095+
if handler:
1096+
res = handler(recordset, barcode)
1097+
if res:
1098+
return res
1099+
10871100
return self._scan_document__fallback()
10881101

10891102
def list_stock_pickings(self):

0 commit comments

Comments
 (0)