Fix datasync bug for CORE API -> Rattail

This commit is contained in:
Lance Edgar 2022-08-21 11:33:51 -05:00
parent 82ad5ad441
commit 7eb7c25172
3 changed files with 59 additions and 43 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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 = [
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 = [
extensions = {
'_corepos': [
'corepos_account_id',
]
],
}
class MemberImporter(importing.model.MemberImporter):
extension_attr = '_corepos'
extension_fields = [
extensions = {
'_corepos': [
'corepos_account_id',
]
],
}
class StoreImporter(importing.model.StoreImporter):
extension_attr = '_corepos'
extension_fields = [
extensions = {
'_corepos': [
'corepos_id',
]
],
}
class DepartmentImporter(importing.model.DepartmentImporter):
extension_attr = '_corepos'
extension_fields = [
extensions = {
'_corepos': [
'corepos_number',
]
],
}
class SubdepartmentImporter(importing.model.SubdepartmentImporter):
extension_attr = '_corepos'
extension_fields = [
extensions = {
'_corepos': [
'corepos_number',
]
],
}
class VendorImporter(importing.model.VendorImporter):
extension_attr = '_corepos'
extension_fields = [
extensions = {
'_corepos': [
'corepos_id',
]
],
}
class ProductImporter(importing.model.ProductImporter):
extension_attr = '_corepos'
extension_fields = [
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 = [
extensions = {
'_corepos': [
'corepos_id',
]
],
}
def cache_query(self):
query = super(ProductCostImporter, self).cache_query()