Add support for Rattail -> CORE export/sync for Member data
also refactor CORE -> Rattail logic to use `api.set_member()` etc.
This commit is contained in:
parent
8d47a1449c
commit
cb63644c7d
6 changed files with 326 additions and 79 deletions
|
@ -152,21 +152,23 @@ class FromRattailToCore(NewDataSyncImportConsumer):
|
|||
# also establish the API client for each!
|
||||
importer.establish_api()
|
||||
|
||||
# sync all Department changes
|
||||
# sync all Customer changes
|
||||
types = [
|
||||
'Department',
|
||||
'Customer',
|
||||
'Person',
|
||||
'CustomerPerson',
|
||||
]
|
||||
for change in [c for c in changes if c.payload_type in types]:
|
||||
if change.payload_type == 'Department' and change.deletion:
|
||||
# TODO: we have no way (yet) to delete a CORE department via API
|
||||
if change.payload_type == 'Customer' and change.deletion:
|
||||
# # just do default logic for this one
|
||||
# self.invoke_importer(session, change)
|
||||
# TODO: we have no way to delete a CORE customer via API, right?
|
||||
pass
|
||||
else: # we consider this an "add/update"
|
||||
department = self.get_department(session, change)
|
||||
if department:
|
||||
self.process_change(session, self.importers['Department'],
|
||||
host_object=department)
|
||||
customers = self.get_customers(session, change)
|
||||
for customer in customers:
|
||||
self.process_change(session, self.importers['Member'],
|
||||
host_object=customer)
|
||||
|
||||
# sync all Vendor changes
|
||||
types = [
|
||||
|
@ -186,9 +188,53 @@ class FromRattailToCore(NewDataSyncImportConsumer):
|
|||
self.process_change(session, self.importers['Vendor'],
|
||||
host_object=vendor)
|
||||
|
||||
def get_department(self, session, change):
|
||||
if change.payload_type == 'Department':
|
||||
return session.query(model.Department).get(change.payload_key)
|
||||
# sync all Product changes
|
||||
types = [
|
||||
'Product',
|
||||
'ProductPrice',
|
||||
]
|
||||
for change in [c for c in changes if c.payload_type in types]:
|
||||
if change.payload_type == 'Product' and change.deletion:
|
||||
# # just do default logic for this one
|
||||
# self.invoke_importer(session, change)
|
||||
# TODO: we have no way to delete a CORE product via API, right?
|
||||
pass
|
||||
else: # we consider this an "add/update"
|
||||
product = self.get_product(session, change)
|
||||
if product:
|
||||
self.process_change(session, self.importers['Product'],
|
||||
host_object=product)
|
||||
|
||||
# process all remaining supported models with typical logic
|
||||
types = [
|
||||
'Department',
|
||||
'Subdepartment',
|
||||
]
|
||||
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):
|
||||
return session.query(getattr(model, change.payload_type))\
|
||||
.get(change.payload_key)
|
||||
|
||||
def get_customers(self, session, change):
|
||||
|
||||
if change.payload_type == 'Customer':
|
||||
customer = session.query(model.Customer).get(change.payload_key)
|
||||
if customer:
|
||||
return [customer]
|
||||
|
||||
if change.payload_type == 'CustomerPerson':
|
||||
cp = session.query(model.CustomerPerson).get(change.payload_key)
|
||||
if cp:
|
||||
return [cp.customer]
|
||||
|
||||
if change.payload_type == 'Person':
|
||||
person = session.query(model.Person).get(change.payload_key)
|
||||
if person:
|
||||
return person.customers
|
||||
|
||||
return []
|
||||
|
||||
def get_vendor(self, session, change):
|
||||
|
||||
|
@ -204,3 +250,13 @@ class FromRattailToCore(NewDataSyncImportConsumer):
|
|||
email = session.query(model.VendorEmailAddress).get(change.payload_key)
|
||||
if email:
|
||||
return email.vendor
|
||||
|
||||
def get_product(self, session, change):
|
||||
|
||||
if change.payload_type == 'Product':
|
||||
return session.query(model.Product).get(change.payload_key)
|
||||
|
||||
if change.payload_type == 'ProductPrice':
|
||||
price = session.query(model.ProductPrice).get(change.payload_key)
|
||||
if price:
|
||||
return price.product
|
||||
|
|
|
@ -86,7 +86,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
|
|||
|
||||
def get_host_object(self, session, change):
|
||||
if change.payload_type == 'Customer':
|
||||
return self.api.get_customer(change.payload_key)
|
||||
return self.api.get_member(change.payload_key)
|
||||
if change.payload_type == 'Department':
|
||||
return self.api.get_department(change.payload_key)
|
||||
if change.payload_type == 'Subdepartment':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue