Fix how customerAccountID is imported from CORE API

geez.

also optimize joinedloads when fetching Rattail member data for CORE
export
This commit is contained in:
Lance Edgar 2023-06-11 15:21:30 -05:00
parent 914fcbe192
commit 2ca9cd8f76
2 changed files with 12 additions and 6 deletions

View file

@ -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

View file

@ -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