Add proper importing for Customer/Person data from CORE API

includes datasync support.  i think it even works right, but we'll see
This commit is contained in:
Lance Edgar 2020-03-16 19:45:54 -05:00
parent 4a409bb80a
commit 8f9f77b6b7
3 changed files with 256 additions and 16 deletions

View file

@ -46,6 +46,44 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
url = self.config.require('corepos.api', 'url')
self.api = CoreWebAPI(url)
def process_changes(self, session, changes):
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()
# sync all Customer-related changes
types = [
'Customer',
]
for change in [c for c in changes if c.payload_type in types]:
if change.deletion:
# normal logic works fine for this (maybe?)
self.invoke_importer(session, change)
else:
# import customer data from API, into various Rattail tables
customer = self.get_host_object(session, change)
self.process_change(session, self.importers['Customer'],
host_object=customer)
people = self.importers['Person'].get_person_objects_for_customer(customer)
for person in people:
self.process_change(session, self.importers['Person'],
host_object=person)
# process all remaining supported models with typical logic
types = [
'Department',
'Subdepartment',
'Vendor',
'Product',
]
for change in [c for c in changes if c.payload_type in types]:
self.invoke_importer(session, change)
def get_host_object(self, session, change):
if change.payload_type == 'Customer':
return self.api.get_customer(change.payload_key)