Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions shopfloor/actions/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class SearchResult:

__slots__ = ("record", "type", "code", "parse_result")

def __init__(self, **kw) -> None:
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion shopfloor_gs1/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import search
from . import barcode_parser

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change really needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not against reverting this change if really you prefer so.

I was just applying the "boy scout rule" to bring this file name in line with naming conventions while I was working in the area.

Loading