Fix CORE API -> Rattail datasync for ProductCost
This commit is contained in:
parent
f61a0a7dd9
commit
67618d4784
|
@ -108,6 +108,14 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
|
|||
self.process_change(session, self.importers['Product'],
|
||||
host_object=product)
|
||||
|
||||
# sync all ProductCost-related changes
|
||||
types = [
|
||||
'VendorItem',
|
||||
]
|
||||
for change in [c for c in changes if c.payload_type in types]:
|
||||
# normal logic works fine here
|
||||
self.invoke_importer(session, change)
|
||||
|
||||
def get_host_object(self, session, change):
|
||||
if change.payload_type == 'Member':
|
||||
return self.api.get_member(change.payload_key)
|
||||
|
|
|
@ -648,10 +648,10 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp
|
|||
"""
|
||||
Importer for product cost data from CORE POS API.
|
||||
"""
|
||||
key = 'corepos_id'
|
||||
key = ('vendor_uuid', 'code')
|
||||
supported_fields = [
|
||||
'corepos_id',
|
||||
'product_upc',
|
||||
'product_uuid',
|
||||
'vendor_uuid',
|
||||
'code',
|
||||
'case_size',
|
||||
|
@ -678,6 +678,9 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp
|
|||
self.progress_loop(cache, self.api.get_products(),
|
||||
message="Caching Products from CORE-POS API")
|
||||
|
||||
self.products_by_item_id = self.cache_model(model.Product,
|
||||
key='item_id')
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.api.get_vendor_items()
|
||||
|
||||
|
@ -702,25 +705,38 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp
|
|||
|
||||
return self.api.get_product(item['upc'])
|
||||
|
||||
def normalize_host_object(self, item):
|
||||
try:
|
||||
upc = GPC(item['upc'], calc_check_digit='upc')
|
||||
except (TypeError, ValueError):
|
||||
log.warning("CORE POS vendor item has invalid UPC: %s", item['upc'])
|
||||
return
|
||||
def get_product(self, item):
|
||||
item_id = item['upc']
|
||||
|
||||
if hasattr(self, 'products_by_item_id'):
|
||||
return self.products_by_item_id.get(item_id)
|
||||
|
||||
model = self.model
|
||||
try:
|
||||
return self.session.query(model.Product)\
|
||||
.filter(model.Product.item_id == item_id)\
|
||||
.one()
|
||||
except orm.exc.NoResultFound:
|
||||
pass
|
||||
|
||||
def normalize_host_object(self, item):
|
||||
vendor = self.get_vendor(item)
|
||||
if not vendor:
|
||||
log.warning("CORE POS vendor not found for item: %s", item)
|
||||
return
|
||||
|
||||
product = self.get_corepos_product(item)
|
||||
product = self.get_product(item)
|
||||
if not product:
|
||||
log.warning("product not found for CORE vendor item: %s", item)
|
||||
return
|
||||
|
||||
core_product = self.get_corepos_product(item)
|
||||
# if not product:
|
||||
# log.warning("CORE POS product not found for item: %s", item)
|
||||
# return
|
||||
|
||||
preferred = False
|
||||
if product and product['default_vendor_id'] == item['vendorID']:
|
||||
if core_product and core_product['default_vendor_id'] == item['vendorID']:
|
||||
preferred = True
|
||||
|
||||
case_size = decimal.Decimal(item['units'])
|
||||
|
@ -728,7 +744,7 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp
|
|||
|
||||
return {
|
||||
'corepos_id': int(item['vendorItemID']),
|
||||
'product_upc': upc,
|
||||
'product_uuid': product.uuid,
|
||||
'vendor_uuid': vendor.uuid,
|
||||
'code': (item['sku'] or '').strip() or None,
|
||||
'case_size': case_size,
|
||||
|
|
Loading…
Reference in a new issue