Warn if user "scans" UPC with more than 14 digits, for mobile inventory

never assume such a UPC is valid, warn instead of adding batch row
This commit is contained in:
Lance Edgar 2018-01-17 14:45:09 -06:00
parent 07e7c5c4a0
commit dd7c2a0763

View file

@ -235,6 +235,8 @@ class InventoryBatchView(BatchMasterView):
upc = re.sub(r'\D', '', upc) upc = re.sub(r'\D', '', upc)
if upc: if upc:
if len(upc) <= 14:
# try to locate general product by UPC; add to batch either way # try to locate general product by UPC; add to batch either way
provided = GPC(upc, calc_check_digit=False) provided = GPC(upc, calc_check_digit=False)
checked = GPC(upc, calc_check_digit='upc') checked = GPC(upc, calc_check_digit='upc')
@ -250,6 +252,10 @@ class InventoryBatchView(BatchMasterView):
row.description = "(unknown product)" row.description = "(unknown product)"
self.handler.add_row(batch, row) self.handler.add_row(batch, row)
else:
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
self.Session.flush() self.Session.flush()
return self.redirect(self.mobile_row_route_url('view', uuid=row.batch_uuid, row_uuid=row.uuid)) return self.redirect(self.mobile_row_route_url('view', uuid=row.batch_uuid, row_uuid=row.uuid))