From aff04035ff36b0a76520ba794c79ff0058d7bf70 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 4 Sep 2020 20:22:24 -0500 Subject: [PATCH] Add datasync support for CORE VendorItem -> ProductCost --- rattail_corepos/datasync/rattail.py | 10 ++++++++++ rattail_corepos/importing/corepos/api.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rattail_corepos/datasync/rattail.py b/rattail_corepos/datasync/rattail.py index c472f1c..b627264 100644 --- a/rattail_corepos/datasync/rattail.py +++ b/rattail_corepos/datasync/rattail.py @@ -37,6 +37,9 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer): Consumer for CORE POS (API) -> Rattail datasync """ handler_spec = 'rattail_corepos.importing.corepos.api:FromCOREPOSToRattail' + model_map = { + 'VendorItem': 'ProductCost', + } def setup(self): super(FromCOREAPIToRattail, self).setup() @@ -82,6 +85,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer): 'Subdepartment', 'Vendor', 'Product', + 'VendorItem', ] for change in [c for c in changes if c.payload_type in types]: self.invoke_importer(session, change) @@ -97,6 +101,12 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer): return self.api.get_vendor(change.payload_key) 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 vendorID.isdigit(): + return self.api.get_vendor_item(upc, int(vendorID)) class FromCOREPOSToRattailBase(NewDataSyncImportConsumer): diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index 6cb8c39..137b90e 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -614,6 +614,7 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp if hasattr(self, 'vendors'): return self.vendors.get(corepos_id) + model = self.config.get_model() try: return self.session.query(model.Vendor)\ .join(model.CoreVendor)\ @@ -626,7 +627,7 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp if hasattr(self, 'corepos_products'): return self.corepos_products.get(item['upc']) - return self.api.get_vendor_item(item['upc'], item['vendorID']) + return self.api.get_product(item['upc']) def normalize_host_object(self, item): try: