From 2ca9cd8f76e8aba305723b1d63c3a59093f6a7c8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 11 Jun 2023 15:21:30 -0500 Subject: [PATCH] Fix how customerAccountID is imported from CORE API geez. also optimize joinedloads when fetching Rattail member data for CORE export --- rattail_corepos/corepos/office/importing/rattail.py | 13 +++++++++++-- rattail_corepos/importing/corepos/api.py | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rattail_corepos/corepos/office/importing/rattail.py b/rattail_corepos/corepos/office/importing/rattail.py index 62640a6..3b1eddf 100644 --- a/rattail_corepos/corepos/office/importing/rattail.py +++ b/rattail_corepos/corepos/office/importing/rattail.py @@ -106,8 +106,17 @@ class MemberImporter(FromRattail, corepos_importing.model.MemberImporter): query = super().query() model = self.model - # TODO: should joinedload for CustomerShopper.phones etc. too? - query = query.options(orm.joinedload(model.Customer.addresses)) + query = query.options(orm.joinedload(model.Customer.members))\ + .options(orm.joinedload(model.Customer._corepos))\ + .options(orm.joinedload(model.Customer.addresses))\ + .options(orm.joinedload(model.Customer.shoppers)\ + .joinedload(model.CustomerShopper._corepos))\ + .options(orm.joinedload(model.Customer.shoppers)\ + .joinedload(model.CustomerShopper.person)\ + .joinedload(model.Person.phones))\ + .options(orm.joinedload(model.Customer.shoppers)\ + .joinedload(model.CustomerShopper.person)\ + .joinedload(model.Person.emails)) return query diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index 9f1d01e..c0b0d36 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -172,6 +172,7 @@ class CustomerImporter(FromCOREPOSAPI, corepos_importing.model.CustomerImporter) data = { 'corepos_card_number': card_number, + 'corepos_account_id': int(member['customerAccountID']), 'number': card_number, 'name': normalize_full_name(customer['firstName'], customer['lastName']), @@ -183,10 +184,6 @@ class CustomerImporter(FromCOREPOSAPI, corepos_importing.model.CustomerImporter) 'address_zipcode': member['zip'] or None, } - if 'corepos_account_id' in self.fields: - account_id = customer.get('customerAccountID') - data['corepos_account_id'] = int(account_id) if account_id is not None else None - return data