fix: misc. improvements for CORE API importer, per flaky data

handle some edge cases better; let config dictate whether some
warnings should be logged etc.
This commit is contained in:
Lance Edgar 2024-07-04 13:23:51 -05:00
parent dca2c1bfe2
commit 4752409a45
2 changed files with 63 additions and 21 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -26,8 +26,6 @@ DataSync for Rattail DB
from sqlalchemy import orm
from corepos.db.office_op import Session as CoreSession, model as corepos
from rattail.datasync import DataSyncImportConsumer
@ -143,7 +141,7 @@ class FromCOREAPIToRattail(DataSyncImportConsumer):
if len(fields) == 2:
sku, vendorID = fields
vendor_item = self.api.get_vendor_item(sku, vendorID)
if vendor_item:
if vendor_item and vendor_item.get('upc'):
return self.api.get_product(vendor_item['upc'])
@ -154,7 +152,8 @@ class FromCOREPOSToRattailBase(DataSyncImportConsumer):
handler_spec = 'rattail_corepos.importing.corepos.db:FromCOREPOSToRattail'
def begin_transaction(self):
self.corepos_session = CoreSession()
corepos = self.app.get_corepos_handler()
self.corepos_session = corepos.make_session_office_op()
def rollback_transaction(self):
self.corepos_session.rollback()
@ -172,16 +171,18 @@ class FromCOREPOSToRattailProducts(FromCOREPOSToRattailBase):
"""
def get_host_object(self, session, change):
corepos = self.app.get_corepos_handler()
op_model = corepos.get_model_office_op()
if change.payload_type == 'Product':
try:
return self.corepos_session.query(corepos.Product)\
.filter(corepos.Product.upc == change.payload_key)\
return self.corepos_session.query(op_model.Product)\
.filter(op_model.Product.upc == change.payload_key)\
.one()
except orm.exc.NoResultFound:
pass
else:
# try to fetch CORE POS object via typical method
Model = getattr(corepos, change.payload_type)
Model = getattr(op_model, change.payload_type)
return self.corepos_session.get(Model, int(change.payload_key))