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: else:
del fs.complete 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 # 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 # probably be changed to require POST; for now we just require the "create
# batch row" perm and call it good.. # batch row" perm and call it good..
@ -243,14 +246,19 @@ class InventoryBatchView(BatchMasterView):
product = api.get_product_by_upc(self.Session(), provided) product = api.get_product_by_upc(self.Session(), provided)
if not product: if not product:
product = api.get_product_by_upc(self.Session(), checked) product = api.get_product_by_upc(self.Session(), checked)
row = model.InventoryBatchRow() if product or self.unknown_product_creates_row:
if product: row = model.InventoryBatchRow()
row.product = product if product:
row.upc = product.upc 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("Product not found: {}".format(upc), 'error')
row.description = "(unknown product)" return self.redirect(self.get_action_url('view', batch, mobile=True))
self.handler.add_row(batch, row)
else: else:
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error') self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')