Let "new product" batch override type-2 UPC lookup behavior
This commit is contained in:
parent
8a61574221
commit
81672e2ded
|
@ -141,7 +141,9 @@ class NewProductBatchHandler(BatchHandler):
|
|||
row.status_code = row.STATUS_MISSING_KEY
|
||||
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:
|
||||
row.status_code = row.STATUS_PRODUCT_EXISTS
|
||||
|
|
|
@ -201,7 +201,8 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
# if entry is GPC then only look for that type of match
|
||||
# TODO: is this really the expected behavior? maybe not..
|
||||
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
|
||||
# TODO: let config declare default lookup_fields
|
||||
|
@ -392,17 +393,22 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
product = None
|
||||
|
||||
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':
|
||||
product = self.locate_product_for_item_id(session, entry)
|
||||
product = self.locate_product_for_item_id(session, entry, **kwargs)
|
||||
|
||||
elif product_key == 'scancode':
|
||||
product = self.locate_product_for_scancode(session, entry)
|
||||
product = self.locate_product_for_scancode(session, entry, **kwargs)
|
||||
|
||||
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.
|
||||
|
||||
|
@ -410,6 +416,11 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
|
||||
: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`
|
||||
instance found if there was a match; otherwise ``None``.
|
||||
"""
|
||||
|
@ -438,10 +449,13 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
return product
|
||||
|
||||
# maybe also try special search for "Type 2 UPC"
|
||||
if gpc.type2_upc and self.convert_type2_for_gpc_lookup():
|
||||
cleaned = self.make_gpc('002{}00000'.format(gpc.data_str[1:6]),
|
||||
calc_check_digit='upc')
|
||||
return lookup(cleaned)
|
||||
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]),
|
||||
calc_check_digit='upc')
|
||||
return lookup(cleaned)
|
||||
|
||||
def convert_type2_for_gpc_lookup(self):
|
||||
return self.config.getbool(
|
||||
|
|
Loading…
Reference in a new issue