Allow lookup of inventory item by alternate code
i.e. in addition to UPC. but only if so configured
This commit is contained in:
parent
177d9d2e3d
commit
b515331e48
|
@ -324,25 +324,39 @@ class InventoryBatchView(BatchMasterView):
|
|||
'redirect': self.get_action_url('view', batch),
|
||||
}
|
||||
data = {}
|
||||
upc = self.request.GET.get('upc', '').strip()
|
||||
upc = re.sub(r'\D', '', upc)
|
||||
entry = self.request.GET.get('upc', '')
|
||||
product = self.find_product(entry)
|
||||
data = self.product_info(product)
|
||||
|
||||
result = {'product': data or None, 'upc_raw': entry, 'upc': None}
|
||||
if not data:
|
||||
upc = re.sub(r'\D', '', entry.strip())
|
||||
if upc:
|
||||
upc = GPC(upc)
|
||||
result['upc'] = six.text_type(upc)
|
||||
result['upc_pretty'] = upc.pretty()
|
||||
result['image_url'] = pod.get_image_url(self.rattail_config, upc)
|
||||
return result
|
||||
|
||||
def find_product(self, entry):
|
||||
upc = re.sub(r'\D', '', entry.strip())
|
||||
if upc:
|
||||
|
||||
# first try to locate existing batch row by UPC match
|
||||
provided = GPC(upc, calc_check_digit=False)
|
||||
checked = GPC(upc, 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)
|
||||
data = self.product_info(product)
|
||||
if product:
|
||||
return product
|
||||
product = api.get_product_by_upc(self.Session(), checked)
|
||||
if product:
|
||||
return product
|
||||
|
||||
result = {'product': data or None, 'upc_raw': upc, 'upc': None}
|
||||
if not data and upc:
|
||||
upc = GPC(upc)
|
||||
result['upc'] = six.text_type(upc)
|
||||
result['upc_pretty'] = upc.pretty()
|
||||
result['image_url'] = pod.get_image_url(self.rattail_config, upc)
|
||||
return result
|
||||
# maybe try to locate product by alternate code
|
||||
if self.rattail_config.getbool('tailbone', 'inventory.lookup_by_code', default=False):
|
||||
product = api.get_product_by_code(self.Session(), entry)
|
||||
if product:
|
||||
return product
|
||||
|
||||
def product_info(self, product):
|
||||
data = {}
|
||||
|
|
Loading…
Reference in a new issue