From 77bd9e34e4eed924db8396c3c8e29faf6306af0e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 10 Jun 2023 22:29:50 -0500 Subject: [PATCH] Be smarter about member datasync for Rattail -> CORE per new CustomerShopper schema etc. --- rattail_corepos/datasync/corepos.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/rattail_corepos/datasync/corepos.py b/rattail_corepos/datasync/corepos.py index 685a2ab..1668181 100644 --- a/rattail_corepos/datasync/corepos.py +++ b/rattail_corepos/datasync/corepos.py @@ -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]