Fix datasync bug for CORE API -> Rattail
This commit is contained in:
parent
82ad5ad441
commit
7eb7c25172
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2021 Lance Edgar
|
# Copyright © 2010-2022 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
DataSync for Rattail DB
|
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
|
from corepos.db.office_op import Session as CoreSession, model as corepos
|
||||||
|
|
||||||
|
@ -48,15 +48,18 @@ class FromCOREAPIToRattail(DataSyncImportConsumer):
|
||||||
def establish_api(self):
|
def establish_api(self):
|
||||||
self.api = make_corepos_api(self.config)
|
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:
|
if self.runas_username:
|
||||||
session.set_continuum_user(self.runas_username)
|
session.set_continuum_user(self.runas_username)
|
||||||
|
|
||||||
# update all importers with current Rattail session
|
# update all importers with current Rattail session
|
||||||
for importer in self.importers.values():
|
for importer in self.importers.values():
|
||||||
importer.session = session
|
importer.session = session
|
||||||
# also establish the API client for each!
|
importer.datasync_setup()
|
||||||
importer.establish_api()
|
|
||||||
|
def process_changes_proper(self, session, changes):
|
||||||
|
|
||||||
# sync all Customer-related changes
|
# sync all Customer-related changes
|
||||||
types = [
|
types = [
|
||||||
|
@ -176,7 +179,7 @@ class FromCOREPOSToRattailProducts(FromCOREPOSToRattailBase):
|
||||||
return self.corepos_session.query(corepos.Product)\
|
return self.corepos_session.query(corepos.Product)\
|
||||||
.filter(corepos.Product.upc == change.payload_key)\
|
.filter(corepos.Product.upc == change.payload_key)\
|
||||||
.one()
|
.one()
|
||||||
except NoResultFound:
|
except orm.exc.NoResultFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -84,6 +84,10 @@ class FromCOREPOSAPI(importing.Importer):
|
||||||
super(FromCOREPOSAPI, self).setup()
|
super(FromCOREPOSAPI, self).setup()
|
||||||
self.establish_api()
|
self.establish_api()
|
||||||
|
|
||||||
|
def datasync_setup(self):
|
||||||
|
super(FromCOREPOSAPI, self).datasync_setup()
|
||||||
|
self.establish_api()
|
||||||
|
|
||||||
def establish_api(self):
|
def establish_api(self):
|
||||||
self.api = make_corepos_api(self.config)
|
self.api = make_corepos_api(self.config)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2021 Lance Edgar
|
# Copyright © 2010-2022 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -36,10 +36,11 @@ from rattail.util import pretty_quantity
|
||||||
|
|
||||||
class PersonImporter(importing.model.PersonImporter):
|
class PersonImporter(importing.model.PersonImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_customer_id',
|
'corepos_customer_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def cache_query(self):
|
def cache_query(self):
|
||||||
query = super(PersonImporter, self).cache_query()
|
query = super(PersonImporter, self).cache_query()
|
||||||
|
@ -55,58 +56,65 @@ class PersonImporter(importing.model.PersonImporter):
|
||||||
|
|
||||||
class CustomerImporter(importing.model.CustomerImporter):
|
class CustomerImporter(importing.model.CustomerImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_account_id',
|
'corepos_account_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class MemberImporter(importing.model.MemberImporter):
|
class MemberImporter(importing.model.MemberImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_account_id',
|
'corepos_account_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class StoreImporter(importing.model.StoreImporter):
|
class StoreImporter(importing.model.StoreImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_id',
|
'corepos_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DepartmentImporter(importing.model.DepartmentImporter):
|
class DepartmentImporter(importing.model.DepartmentImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_number',
|
'corepos_number',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SubdepartmentImporter(importing.model.SubdepartmentImporter):
|
class SubdepartmentImporter(importing.model.SubdepartmentImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_number',
|
'corepos_number',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class VendorImporter(importing.model.VendorImporter):
|
class VendorImporter(importing.model.VendorImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_id',
|
'corepos_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ProductImporter(importing.model.ProductImporter):
|
class ProductImporter(importing.model.ProductImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_id',
|
'corepos_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
super(ProductImporter, self).setup()
|
super(ProductImporter, self).setup()
|
||||||
|
@ -178,10 +186,11 @@ class ProductImporter(importing.model.ProductImporter):
|
||||||
|
|
||||||
class ProductCostImporter(importing.model.ProductCostImporter):
|
class ProductCostImporter(importing.model.ProductCostImporter):
|
||||||
|
|
||||||
extension_attr = '_corepos'
|
extensions = {
|
||||||
extension_fields = [
|
'_corepos': [
|
||||||
'corepos_id',
|
'corepos_id',
|
||||||
]
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def cache_query(self):
|
def cache_query(self):
|
||||||
query = super(ProductCostImporter, self).cache_query()
|
query = super(ProductCostImporter, self).cache_query()
|
||||||
|
|
Loading…
Reference in a new issue