From 9b00de26c67122092d268e15c1b979f4e08973d0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 27 Jan 2021 10:12:46 -0600 Subject: [PATCH] Be sure to update Rattail Product, when VendorItem changes in CORE b/c of the `Product.case_size` field --- rattail_corepos/datasync/rattail.py | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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): """