Be smarter about member datasync for Rattail -> CORE

per new CustomerShopper schema etc.
This commit is contained in:
Lance Edgar 2023-06-10 22:29:50 -05:00
parent 6e50ea58a8
commit 77bd9e34e4

View file

@ -169,9 +169,10 @@ class FromRattailToCore(DataSyncImportConsumer):
# also establish the API client for each!
importer.establish_api()
# sync all Customer changes
# sync all Member changes
types = [
'Customer',
'CustomerShopper',
'Person',
'CustomerPerson',
'CustomerMailingAddress',
@ -238,38 +239,44 @@ class FromRattailToCore(DataSyncImportConsumer):
return session.get(getattr(model, change.payload_type), change.payload_key)
def get_customers(self, session, change):
clientele = self.app.get_clientele_handler()
if change.payload_type == 'Customer':
customer = session.get(model.Customer, change.payload_key)
if customer:
return [customer]
if change.payload_type == 'CustomerPerson':
elif change.payload_type == 'CustomerShopper':
shopper = session.get(model.CustomerShopper, change.payload_key)
if shopper:
return [shopper.customer]
elif change.payload_type == 'CustomerPerson':
cp = session.get(model.CustomerPerson, change.payload_key)
if cp:
return [cp.customer]
if change.payload_type == 'Person':
elif change.payload_type == 'Person':
person = session.get(model.Person, change.payload_key)
if person:
return person.customers
return clientele.get_customers_for_account_holder(person)
if change.payload_type == 'CustomerMailingAddress':
elif change.payload_type == 'CustomerMailingAddress':
address = session.get(model.CustomerMailingAddress, change.payload_key)
if address:
return [address.customer]
if change.payload_type == 'PersonPhoneNumber':
elif change.payload_type == 'PersonPhoneNumber':
phone = session.get(model.PersonPhoneNumber, change.payload_key)
if phone:
return phone.person.customers
return clientele.get_customers_for_account_holder(phone.person)
if change.payload_type == 'PersonEmailAddress':
elif change.payload_type == 'PersonEmailAddress':
email = session.get(model.PersonEmailAddress, change.payload_key)
if email:
return email.person.customers
return clientele.get_customers_for_account_holder(email.person)
if change.payload_type == 'Member':
elif change.payload_type == 'Member':
member = session.get(model.Member, change.payload_key)
if member:
return [member.customer]