Import member first/last name from CORE API

This commit is contained in:
Lance Edgar 2023-09-13 13:15:25 -05:00
parent f6c08af32c
commit 64048db92f

View file

@ -789,7 +789,8 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
'number', 'number',
'corepos_account_id', 'corepos_account_id',
'customer_uuid', 'customer_uuid',
'person_uuid', 'person_first_name',
'person_last_name',
'membership_type_number', 'membership_type_number',
'joined', 'joined',
'withdrew', 'withdrew',
@ -832,10 +833,14 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
except orm.exc.NoResultFound: except orm.exc.NoResultFound:
pass pass
def get_corepos_customer(self, corepos_member):
for customer in corepos_member['customers']:
if customer['accountHolder']:
return customer
def normalize_host_object(self, member): def normalize_host_object(self, member):
card_number = member['cardNo'] card_number = member['cardNo']
customer = self.get_customer_by_number(card_number) customer = self.get_customer_by_number(card_number)
person = self.app.get_person(customer) if customer else None
# TODO: at first i was *skipping* non-member status records, # TODO: at first i was *skipping* non-member status records,
# but since CORE sort of assumes all customers are members, # but since CORE sort of assumes all customers are members,
@ -871,13 +876,21 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
member['customerTypeID'], member) member['customerTypeID'], member)
typeno = None typeno = None
return { data = {
'number': card_number, 'number': card_number,
'corepos_account_id': int(member['customerAccountID']), 'corepos_account_id': int(member['customerAccountID']),
'customer_uuid': customer.uuid if customer else None, 'customer_uuid': customer.uuid if customer else None,
'person_uuid': person.uuid if person else None, 'person_first_name': None,
'person_last_name': None,
'membership_type_number': typeno, 'membership_type_number': typeno,
'joined': joined, 'joined': joined,
'withdrew': withdrew, 'withdrew': withdrew,
'active': not bool(withdrew), 'active': not bool(withdrew),
} }
corepos_customer = self.get_corepos_customer(member)
if corepos_customer:
data['person_first_name'] = corepos_customer['firstName']
data['person_last_name'] = corepos_customer['lastName']
return data