diff --git a/rattail_corepos/datasync/rattail.py b/rattail_corepos/datasync/rattail.py index f929682..49238a5 100644 --- a/rattail_corepos/datasync/rattail.py +++ b/rattail_corepos/datasync/rattail.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2022 Lance Edgar # # This file is part of Rattail. # @@ -24,7 +24,7 @@ DataSync for Rattail DB """ -from sqlalchemy.orm.exc import NoResultFound +from sqlalchemy import orm from corepos.db.office_op import Session as CoreSession, model as corepos @@ -48,15 +48,18 @@ class FromCOREAPIToRattail(DataSyncImportConsumer): def establish_api(self): self.api = make_corepos_api(self.config) - def process_changes(self, session, changes): + def pre_process_changes(self, session, changes): + + # declare user responsible if self.runas_username: session.set_continuum_user(self.runas_username) # update all importers with current Rattail session for importer in self.importers.values(): importer.session = session - # also establish the API client for each! - importer.establish_api() + importer.datasync_setup() + + def process_changes_proper(self, session, changes): # sync all Customer-related changes types = [ @@ -176,7 +179,7 @@ class FromCOREPOSToRattailProducts(FromCOREPOSToRattailBase): return self.corepos_session.query(corepos.Product)\ .filter(corepos.Product.upc == change.payload_key)\ .one() - except NoResultFound: + except orm.exc.NoResultFound: pass else: diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index 728a380..cc40e7b 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -84,6 +84,10 @@ class FromCOREPOSAPI(importing.Importer): super(FromCOREPOSAPI, self).setup() self.establish_api() + def datasync_setup(self): + super(FromCOREPOSAPI, self).datasync_setup() + self.establish_api() + def establish_api(self): self.api = make_corepos_api(self.config) diff --git a/rattail_corepos/importing/model.py b/rattail_corepos/importing/model.py index 861574a..58b12ef 100644 --- a/rattail_corepos/importing/model.py +++ b/rattail_corepos/importing/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2022 Lance Edgar # # This file is part of Rattail. # @@ -36,10 +36,11 @@ from rattail.util import pretty_quantity class PersonImporter(importing.model.PersonImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_customer_id', - ] + extensions = { + '_corepos': [ + 'corepos_customer_id', + ], + } def cache_query(self): query = super(PersonImporter, self).cache_query() @@ -55,58 +56,65 @@ class PersonImporter(importing.model.PersonImporter): class CustomerImporter(importing.model.CustomerImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_account_id', - ] + extensions = { + '_corepos': [ + 'corepos_account_id', + ], + } class MemberImporter(importing.model.MemberImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_account_id', - ] + extensions = { + '_corepos': [ + 'corepos_account_id', + ], + } class StoreImporter(importing.model.StoreImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_id', - ] + extensions = { + '_corepos': [ + 'corepos_id', + ], + } class DepartmentImporter(importing.model.DepartmentImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_number', - ] + extensions = { + '_corepos': [ + 'corepos_number', + ], + } class SubdepartmentImporter(importing.model.SubdepartmentImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_number', - ] + extensions = { + '_corepos': [ + 'corepos_number', + ], + } class VendorImporter(importing.model.VendorImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_id', - ] + extensions = { + '_corepos': [ + 'corepos_id', + ], + } class ProductImporter(importing.model.ProductImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_id', - ] + extensions = { + '_corepos': [ + 'corepos_id', + ], + } def setup(self): super(ProductImporter, self).setup() @@ -178,10 +186,11 @@ class ProductImporter(importing.model.ProductImporter): class ProductCostImporter(importing.model.ProductCostImporter): - extension_attr = '_corepos' - extension_fields = [ - 'corepos_id', - ] + extensions = { + '_corepos': [ + 'corepos_id', + ], + } def cache_query(self): query = super(ProductCostImporter, self).cache_query()