diff --git a/shopfloor/actions/search.py b/shopfloor/actions/search.py index ff6e4350b98..12856f7baa5 100644 --- a/shopfloor/actions/search.py +++ b/shopfloor/actions/search.py @@ -8,7 +8,6 @@ class SearchResult: - __slots__ = ("record", "type", "code", "parse_result") def __init__(self, **kw) -> None: @@ -95,8 +94,11 @@ def generic_find(self, barcode, types=None, handler_kw=None): _types = types or self._barcode_type_handler.keys() # TODO: decide the best default order in case we don't pass `types` parse_results = self.parser.parse(barcode, types) - for parse_result in parse_results: - for btype in _types: + # OPTIMIZATION: Push 'unknown' types to the end so that we return earlier + # in case the type is known after parsing + for parse_result in sorted(parse_results, key=lambda r: r.type == "unknown"): + btypes = _types if parse_result.type == "unknown" else [parse_result.type] + for btype in btypes: record = self._find_record_by_type( parse_result.value, btype, handler_kw ) diff --git a/shopfloor_gs1/actions/__init__.py b/shopfloor_gs1/actions/__init__.py index 74d7cf6a341..056e2b5dba0 100644 --- a/shopfloor_gs1/actions/__init__.py +++ b/shopfloor_gs1/actions/__init__.py @@ -1 +1 @@ -from . import search +from . import barcode_parser diff --git a/shopfloor_gs1/actions/search.py b/shopfloor_gs1/actions/barcode_parser.py similarity index 100% rename from shopfloor_gs1/actions/search.py rename to shopfloor_gs1/actions/barcode_parser.py