diff --git a/rattail_corepos/datasync/rattail.py b/rattail_corepos/datasync/rattail.py index b627264..5fd0a04 100644 --- a/rattail_corepos/datasync/rattail.py +++ b/rattail_corepos/datasync/rattail.py @@ -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]: - self.invoke_importer(session, change) + + # 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): """