Capture user input for mobile receiving, and move some lookup logic
i.e. most of the logic responsible for looking up an item from e.g. scanner entry, now lives in the handler for easier customization
This commit is contained in:
parent
ed5455089e
commit
878486cdab
|
@ -1030,35 +1030,12 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
def quick_locate_product(self, batch, entry):
|
||||
|
||||
# try to locate product by uuid before other, more specific key
|
||||
product = self.Session.query(model.Product).get(entry)
|
||||
# first let the handler attempt lookup on product key (only)
|
||||
product = self.handler.locate_product_for_entry(self.Session(), entry,
|
||||
lookup_by_code=False)
|
||||
if product:
|
||||
return product
|
||||
|
||||
key = self.rattail_config.product_key()
|
||||
if key == 'upc':
|
||||
|
||||
# we first assume the user entry *does* include check digit
|
||||
provided = GPC(entry, calc_check_digit=False)
|
||||
product = api.get_product_by_upc(self.Session(), provided)
|
||||
if product:
|
||||
return product
|
||||
|
||||
# but we can also calculate a check digit and try that
|
||||
checked = GPC(entry, calc_check_digit='upc')
|
||||
product = api.get_product_by_upc(self.Session(), checked)
|
||||
if product:
|
||||
return product
|
||||
|
||||
elif key == 'item_id':
|
||||
|
||||
# try to locate product by item_id
|
||||
product = api.get_product_by_item_id(self.Session(), entry)
|
||||
if product:
|
||||
return product
|
||||
|
||||
# if we made it this far, lookup by product key failed.
|
||||
|
||||
# now we'll attempt lookup by vendor item code
|
||||
product = api.get_product_by_vendor_code(self.Session(), entry, vendor=batch.vendor)
|
||||
if product:
|
||||
|
@ -1088,6 +1065,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
else: # borrow product from matching row, but make new row
|
||||
other_row = rows[0]
|
||||
row = model.PurchaseBatchRow()
|
||||
row.item_entry = entry
|
||||
row.product = other_row.product
|
||||
self.handler.add_row(batch, row)
|
||||
self.Session.flush()
|
||||
|
@ -1099,6 +1077,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
# TODO: probably should be smarter about how we handle deleted?
|
||||
if product and not product.deleted:
|
||||
row = model.PurchaseBatchRow()
|
||||
row.item_entry = entry
|
||||
row.product = product
|
||||
self.handler.add_row(batch, row)
|
||||
self.Session.flush()
|
||||
|
@ -1117,6 +1096,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# product not in system, but presumably sane upc, so add to batch anyway
|
||||
row = model.PurchaseBatchRow()
|
||||
row.item_entry = entry
|
||||
add_check_digit = True # TODO: make this dynamic, of course
|
||||
if add_check_digit:
|
||||
row.upc = checked
|
||||
|
@ -1137,6 +1117,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# product not in system, but presumably sane item_id, so add to batch anyway
|
||||
row = model.PurchaseBatchRow()
|
||||
row.item_entry = entry
|
||||
row.item_id = entry
|
||||
row.description = "(unknown product)"
|
||||
self.handler.add_row(batch, row)
|
||||
|
|
Loading…
Reference in a new issue