Let "new product" batch override type-2 UPC lookup behavior

This commit is contained in:
Lance Edgar 2023-08-30 20:09:46 -05:00
parent 8a61574221
commit 81672e2ded
2 changed files with 26 additions and 10 deletions

View file

@ -141,7 +141,9 @@ class NewProductBatchHandler(BatchHandler):
row.status_code = row.STATUS_MISSING_KEY row.status_code = row.STATUS_MISSING_KEY
return return
row.product = self.locate_product_for_entry(session, row.item_entry) row.product = self.locate_product_for_entry(
session, row.item_entry,
type2_lookup=row.batch.get_param('type2_lookup'))
if row.product: if row.product:
row.status_code = row.STATUS_PRODUCT_EXISTS row.status_code = row.STATUS_PRODUCT_EXISTS

View file

@ -201,7 +201,8 @@ class ProductsHandler(GenericHandler, MergeMixin):
# if entry is GPC then only look for that type of match # if entry is GPC then only look for that type of match
# TODO: is this really the expected behavior? maybe not.. # TODO: is this really the expected behavior? maybe not..
if isinstance(entry, GPC): if isinstance(entry, GPC):
return self.locate_product_for_gpc(session, entry) return self.locate_product_for_gpc(session, entry,
type2_lookup=kwargs.get('type2_lookup'))
# figure out which fields we should match on # figure out which fields we should match on
# TODO: let config declare default lookup_fields # TODO: let config declare default lookup_fields
@ -392,17 +393,22 @@ class ProductsHandler(GenericHandler, MergeMixin):
product = None product = None
if product_key == 'upc': if product_key == 'upc':
product = self.locate_product_for_upc(session, entry) product = self.locate_product_for_upc(session, entry, **kwargs)
elif product_key == 'item_id': elif product_key == 'item_id':
product = self.locate_product_for_item_id(session, entry) product = self.locate_product_for_item_id(session, entry, **kwargs)
elif product_key == 'scancode': elif product_key == 'scancode':
product = self.locate_product_for_scancode(session, entry) product = self.locate_product_for_scancode(session, entry, **kwargs)
return product return product
def locate_product_for_gpc(self, session, gpc, **kwargs): def locate_product_for_gpc(
self,
session,
gpc,
type2_lookup=None,
**kwargs):
""" """
Try to locate a product for the given GPC value. Try to locate a product for the given GPC value.
@ -410,6 +416,11 @@ class ProductsHandler(GenericHandler, MergeMixin):
:param gpc: :class:`~rattail.gpc.GPC` instance to match on. :param gpc: :class:`~rattail.gpc.GPC` instance to match on.
:param type2_lookup: Optional boolean indicating whether a
"type 2" UPC lookup should be attempted, if applicable. By
default, config will determine whether a type 2 lookup may
be attempted.
:returns: First :class:`~rattail.db.model.products.Product` :returns: First :class:`~rattail.db.model.products.Product`
instance found if there was a match; otherwise ``None``. instance found if there was a match; otherwise ``None``.
""" """
@ -438,7 +449,10 @@ class ProductsHandler(GenericHandler, MergeMixin):
return product return product
# maybe also try special search for "Type 2 UPC" # maybe also try special search for "Type 2 UPC"
if gpc.type2_upc and self.convert_type2_for_gpc_lookup(): if gpc.type2_upc:
if type2_lookup is None:
type2_lookup = self.convert_type2_for_gpc_lookup()
if type2_lookup:
cleaned = self.make_gpc('002{}00000'.format(gpc.data_str[1:6]), cleaned = self.make_gpc('002{}00000'.format(gpc.data_str[1:6]),
calc_check_digit='upc') calc_check_digit='upc')
return lookup(cleaned) return lookup(cleaned)