Do quick lookup by vendor item code, alt code for mobile receiving
at least until we have to make that configurable etc.
This commit is contained in:
parent
acd8c97afc
commit
66f1ed0e41
|
@ -1006,6 +1006,47 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if row.item_id == entry]
|
||||
return rows
|
||||
|
||||
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)
|
||||
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:
|
||||
return product
|
||||
|
||||
# okay then, let's attempt lookup by "alternate" code
|
||||
product = api.get_product_by_code(self.Session(), entry)
|
||||
if product:
|
||||
return product
|
||||
|
||||
def save_quick_row_form(self, form):
|
||||
batch = self.get_instance()
|
||||
entry = form.validated['quick_entry']
|
||||
|
@ -1031,8 +1072,9 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
self.handler.refresh_batch_status(batch)
|
||||
return row
|
||||
|
||||
# try to locate product by uuid before other, more specific key
|
||||
product = self.Session.query(model.Product).get(entry)
|
||||
# if product is easily located, add new row for it
|
||||
product = self.quick_locate_product(batch, entry)
|
||||
# TODO: probably should be smarter about how we handle deleted?
|
||||
if product and not product.deleted:
|
||||
row = model.PurchaseBatchRow()
|
||||
row.product = product
|
||||
|
@ -1044,24 +1086,13 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
key = self.rattail_config.product_key()
|
||||
if key == 'upc':
|
||||
|
||||
# try to locate product by upc
|
||||
provided = GPC(entry, calc_check_digit=False)
|
||||
checked = GPC(entry, calc_check_digit='upc')
|
||||
product = api.get_product_by_upc(self.Session(), provided)
|
||||
if not product:
|
||||
product = api.get_product_by_upc(self.Session(), checked)
|
||||
if product:
|
||||
row = model.PurchaseBatchRow()
|
||||
row.product = product
|
||||
self.handler.add_row(batch, row)
|
||||
self.Session.flush()
|
||||
self.handler.refresh_batch_status(batch)
|
||||
return row
|
||||
|
||||
# check for "bad" upc
|
||||
if len(entry) > 14:
|
||||
return
|
||||
|
||||
provided = GPC(entry, calc_check_digit=False)
|
||||
checked = GPC(entry, calc_check_digit='upc')
|
||||
|
||||
# product not in system, but presumably sane upc, so add to batch anyway
|
||||
row = model.PurchaseBatchRow()
|
||||
add_check_digit = True # TODO: make this dynamic, of course
|
||||
|
@ -1078,16 +1109,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
elif key == 'item_id':
|
||||
|
||||
# try to locate product by item_id
|
||||
product = api.get_product_by_item_id(self.Session(), entry)
|
||||
if product:
|
||||
row = model.PurchaseBatchRow()
|
||||
row.product = product
|
||||
self.handler.add_row(batch, row)
|
||||
self.Session.flush()
|
||||
self.handler.refresh_batch_status(batch)
|
||||
return row
|
||||
|
||||
# check for "too long" item_id
|
||||
if len(entry) > maxlen(model.PurchaseBatchRow.item_id):
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue