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:
parent
07e7c5c4a0
commit
dd7c2a0763
|
@ -235,20 +235,26 @@ class InventoryBatchView(BatchMasterView):
|
||||||
upc = re.sub(r'\D', '', upc)
|
upc = re.sub(r'\D', '', upc)
|
||||||
if upc:
|
if upc:
|
||||||
|
|
||||||
# try to locate general product by UPC; add to batch either way
|
if len(upc) <= 14:
|
||||||
provided = GPC(upc, calc_check_digit=False)
|
|
||||||
checked = GPC(upc, calc_check_digit='upc')
|
# try to locate general product by UPC; add to batch either way
|
||||||
product = api.get_product_by_upc(self.Session(), provided)
|
provided = GPC(upc, calc_check_digit=False)
|
||||||
if not product:
|
checked = GPC(upc, calc_check_digit='upc')
|
||||||
product = api.get_product_by_upc(self.Session(), checked)
|
product = api.get_product_by_upc(self.Session(), provided)
|
||||||
row = model.InventoryBatchRow()
|
if not product:
|
||||||
if product:
|
product = api.get_product_by_upc(self.Session(), checked)
|
||||||
row.product = product
|
row = model.InventoryBatchRow()
|
||||||
row.upc = product.upc
|
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:
|
else:
|
||||||
row.upc = provided # TODO: why not 'checked' instead? how to choose?
|
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')
|
||||||
row.description = "(unknown product)"
|
return self.redirect(self.get_action_url('view', batch, mobile=True))
|
||||||
self.handler.add_row(batch, row)
|
|
||||||
|
|
||||||
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))
|
||||||
|
|
Loading…
Reference in a new issue