Allow lookup of inventory item by alternate code

i.e. in addition to UPC.  but only if so configured
This commit is contained in:
Lance Edgar 2018-05-09 15:58:09 -05:00
parent 177d9d2e3d
commit b515331e48

View file

@ -324,25 +324,39 @@ class InventoryBatchView(BatchMasterView):
'redirect': self.get_action_url('view', batch), 'redirect': self.get_action_url('view', batch),
} }
data = {} data = {}
upc = self.request.GET.get('upc', '').strip() entry = self.request.GET.get('upc', '')
upc = re.sub(r'\D', '', 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: if upc:
# first try to locate existing batch row by UPC match # first try to locate existing batch row by UPC match
provided = GPC(upc, calc_check_digit=False) provided = GPC(upc, calc_check_digit=False)
checked = GPC(upc, calc_check_digit='upc') checked = GPC(upc, calc_check_digit='upc')
product = api.get_product_by_upc(self.Session(), provided) product = api.get_product_by_upc(self.Session(), provided)
if not product: if product:
return product
product = api.get_product_by_upc(self.Session(), checked) product = api.get_product_by_upc(self.Session(), checked)
data = self.product_info(product) if product:
return product
result = {'product': data or None, 'upc_raw': upc, 'upc': None} # maybe try to locate product by alternate code
if not data and upc: if self.rattail_config.getbool('tailbone', 'inventory.lookup_by_code', default=False):
upc = GPC(upc) product = api.get_product_by_code(self.Session(), entry)
result['upc'] = six.text_type(upc) if product:
result['upc_pretty'] = upc.pretty() return product
result['image_url'] = pod.get_image_url(self.rattail_config, upc)
return result
def product_info(self, product): def product_info(self, product):
data = {} data = {}