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,20 +235,26 @@ class InventoryBatchView(BatchMasterView):
upc = re.sub(r'\D', '', upc)
if upc:
# try to locate general product by UPC; add to batch either way
provided = GPC(upc, calc_check_digit=False)
checked = GPC(upc, calc_check_digit='upc')
product = api.get_product_by_upc(self.Session(), provided)
if not product:
product = api.get_product_by_upc(self.Session(), checked)
row = model.InventoryBatchRow()
if product:
row.product = product
row.upc = product.upc
if len(upc) <= 14:
# try to locate general product by UPC; add to batch either way
provided = GPC(upc, calc_check_digit=False)
checked = GPC(upc, calc_check_digit='upc')
product = api.get_product_by_upc(self.Session(), provided)
if not product:
product = api.get_product_by_upc(self.Session(), checked)
row = model.InventoryBatchRow()
if product:
row.product = product
row.upc = product.upc
else:
row.upc = provided # TODO: why not 'checked' instead? how to choose?
row.description = "(unknown product)"
self.handler.add_row(batch, row)
else:
row.upc = provided # TODO: why not 'checked' instead? how to choose?
row.description = "(unknown product)"
self.handler.add_row(batch, row)
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()
return self.redirect(self.mobile_row_route_url('view', uuid=row.batch_uuid, row_uuid=row.uuid))