Skip to content
Open
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
11 changes: 8 additions & 3 deletions shopfloor/actions/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,20 @@ def generic_find(self, barcode, types=None, handler_kw=None):
return self._make_search_result(record=record, code=barcode, type=btype)
return self._make_search_result(type="none")

def location_from_scan(self, barcode, limit=1):
def location_from_scan(self, barcode, limit=1, company=None):
model = self.env["stock.location"]
if not barcode:
return model.browse()
base_domain = []
if company:
base_domain = [("company_id", "=", company.id)]
# First search location by barcode
res = model.search([("barcode", "=", barcode)], limit=limit)
domain = AND([base_domain, [("barcode", "=", barcode)]])
res = model.search(domain, limit=limit)
# And only if we have not found through barcode search on the location name
if len(res) < limit:
res |= model.search([("name", "=", barcode)], limit=(limit - len(res)))
domain = AND([base_domain, [("name", "=", barcode)]])
res |= model.search(domain, limit=(limit - len(res)))
return res

def package_from_scan(self, barcode):
Expand Down