Add 2-way sync for customer contact data, for CORE API <-> Rattail

This commit is contained in:
Lance Edgar 2020-03-17 18:52:08 -05:00
parent 15a99164f2
commit 9dbdb81f07
5 changed files with 80 additions and 10 deletions

View file

@ -157,6 +157,9 @@ class FromRattailToCore(NewDataSyncImportConsumer):
'Customer',
'Person',
'CustomerPerson',
'CustomerMailingAddress',
'PersonPhoneNumber',
'PersonEmailAddress',
]
for change in [c for c in changes if c.payload_type in types]:
if change.payload_type == 'Customer' and change.deletion:
@ -234,6 +237,21 @@ class FromRattailToCore(NewDataSyncImportConsumer):
if person:
return person.customers
if change.payload_type == 'CustomerMailingAddress':
address = session.query(model.CustomerMailingAddress).get(change.payload_key)
if address:
return [address.customer]
if change.payload_type == 'PersonPhoneNumber':
phone = session.query(model.PersonPhoneNumber).get(change.payload_key)
if phone:
return phone.person.customers
if change.payload_type == 'PersonEmailAddress':
email = session.query(model.PersonEmailAddress).get(change.payload_key)
if email:
return email.person.customers
return []
def get_vendor(self, session, change):

View file

@ -58,7 +58,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
# sync all Customer-related changes
types = [
'Customer',
'Member',
]
for change in [c for c in changes if c.payload_type in types]:
if change.deletion:
@ -85,7 +85,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
self.invoke_importer(session, change)
def get_host_object(self, session, change):
if change.payload_type == 'Customer':
if change.payload_type == 'Member':
return self.api.get_member(change.payload_key)
if change.payload_type == 'Department':
return self.api.get_department(change.payload_key)