Use custom data model where possible, when importing from CORE API

not sure if this really does much good, but what the heck
This commit is contained in:
Lance Edgar 2020-07-30 21:07:39 -05:00
parent 1fe48d91f6
commit 6dbf7cf174

View file

@ -34,7 +34,6 @@ from sqlalchemy.orm.exc import NoResultFound
from corepos.api import CoreWebAPI from corepos.api import CoreWebAPI
from rattail import importing from rattail import importing
from rattail.db import model
from rattail.gpc import GPC from rattail.gpc import GPC
from rattail.util import OrderedDict from rattail.util import OrderedDict
from rattail.time import localtime, make_utc from rattail.time import localtime, make_utc
@ -219,6 +218,7 @@ class PersonImporter(FromCOREPOSAPI, corepos_importing.model.PersonImporter):
if hasattr(self, 'customers'): if hasattr(self, 'customers'):
return self.customers.get(id) return self.customers.get(id)
model = self.config.get_model()
try: try:
return self.session.query(model.Customer)\ return self.session.query(model.Customer)\
.filter(model.Customer.id == id)\ .filter(model.Customer.id == id)\
@ -305,6 +305,7 @@ class CustomerPersonImporter(FromCOREPOSAPI, importing.model.CustomerPersonImpor
if hasattr(self, 'customers'): if hasattr(self, 'customers'):
return self.customers.get(account_id) return self.customers.get(account_id)
model = self.config.get_model()
try: try:
return self.session.query(model.Customer)\ return self.session.query(model.Customer)\
.join(model.CoreCustomer)\ .join(model.CoreCustomer)\
@ -554,6 +555,7 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
def setup(self): def setup(self):
super(MemberImporter, self).setup() super(MemberImporter, self).setup()
model = self.config.get_model()
self.customers = self.cache_model(model.Customer, key='number') self.customers = self.cache_model(model.Customer, key='number')
def get_host_objects(self): def get_host_objects(self):
@ -563,6 +565,7 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
if hasattr(self, 'customers'): if hasattr(self, 'customers'):
return self.customers.get(number) return self.customers.get(number)
model = self.config.get_model()
try: try:
return self.session.query(model.Customer)\ return self.session.query(model.Customer)\
.filter(model.Customer.number == number)\ .filter(model.Customer.number == number)\