diff --git a/tailbone/views/inventory.py b/tailbone/views/inventory.py index be276b8e..83cc77a3 100644 --- a/tailbone/views/inventory.py +++ b/tailbone/views/inventory.py @@ -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')