Add even better UPC validation for mobile receiving
This commit is contained in:
parent
44dec830e5
commit
9ad8e5b546
|
@ -223,7 +223,9 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
row = None
|
||||
upc = self.request.GET.get('upc', '').strip()
|
||||
upc = re.sub(r'\D', '', upc)
|
||||
if upc:
|
||||
if not upc:
|
||||
self.request.session.flash("Invalid UPC: {}".format(self.request.GET.get('upc')), 'error')
|
||||
return self.redirect(self.get_action_url('view', batch, mobile=True))
|
||||
|
||||
# first try to locate existing batch row by UPC match
|
||||
provided = GPC(upc, calc_check_digit=False)
|
||||
|
@ -252,20 +254,19 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
batch.add_row(row)
|
||||
self.handler.refresh_row(row)
|
||||
|
||||
else:
|
||||
# check for "bad" upc
|
||||
elif len(upc) > 14:
|
||||
self.request.session.flash("Invalid UPC: {}".format(upc), 'error')
|
||||
return self.redirect(self.get_action_url('view', batch, mobile=True))
|
||||
|
||||
# if product not even in system, add to batch anyway..
|
||||
# but only if it was a "sane" UPC
|
||||
if len(upc) <= 14:
|
||||
# product in system, but sane upc, so add to batch anyway
|
||||
else:
|
||||
row = model.PurchaseBatchRow()
|
||||
row.upc = provided # TODO: why not checked? how to know?
|
||||
row.description = "(unknown product)"
|
||||
batch.add_row(row)
|
||||
self.handler.refresh_row(row)
|
||||
self.handler.refresh_batch_status(batch)
|
||||
else:
|
||||
self.request.session.flash("Invalid UPC: {}".format(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))
|
||||
|
|
Loading…
Reference in a new issue