Be sure to update Rattail Product, when VendorItem changes in CORE

b/c of the `Product.case_size` field
This commit is contained in:
Lance Edgar 2021-01-27 10:12:46 -06:00
parent 5b1305ddbd
commit 9b00de26c6

View file

@ -79,16 +79,34 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
self.process_change(session, self.importers['Member'],
host_object=member)
# process all remaining supported models with typical logic
# sync all "product meta" changes
types = [
'Department',
'Subdepartment',
'Vendor',
]
for change in [c for c in changes if c.payload_type in types]:
# normal logic works fine here
self.invoke_importer(session, change)
# sync all Product-related changes
types = [
'Product',
'VendorItem',
]
for change in [c for c in changes if c.payload_type in types]:
# process deletion per usual logic
if change.deletion:
self.invoke_importer(session, change)
if change.payload_type == 'Product':
continue # stop here if we just deleted a Product
# try to process change for Product
product = self.get_product(change)
if product:
self.process_change(session, self.importers['Product'],
host_object=product)
def get_host_object(self, session, change):
if change.payload_type == 'Member':
@ -108,6 +126,16 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
if vendorID.isdigit():
return self.api.get_vendor_item(upc, int(vendorID))
def get_product(self, change):
if change.payload_type == 'Product':
return self.api.get_product(change.payload_key)
if change.payload_type == 'VendorItem':
fields = change.payload_key.split('|')
if len(fields) == 2:
upc, vendorID = fields
if upc:
return self.api.get_product(upc)
class FromCOREPOSToRattailBase(NewDataSyncImportConsumer):
"""