Add option for preventing new inventory batch rows for unknown products

This commit is contained in:
Lance Edgar 2018-01-17 14:55:17 -06:00
parent dd7c2a0763
commit a542cd70da

View file

@ -221,6 +221,9 @@ class InventoryBatchView(BatchMasterView):
else:
del fs.complete
# TODO: document this, maybe move it etc.
unknown_product_creates_row = True
# TODO: this view can create new rows, with only a GET query. that should
# probably be changed to require POST; for now we just require the "create
# batch row" perm and call it good..
@ -243,14 +246,19 @@ class InventoryBatchView(BatchMasterView):
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 product or self.unknown_product_creates_row:
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("Product not found: {}".format(upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
else:
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')