fix: include person_uuid
for Member import from CORE API
so we correctly associate Customer / Person / Member
This commit is contained in:
parent
6f7fa65c09
commit
eb9a1ae4f0
|
@ -29,6 +29,7 @@ import decimal
|
||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from rattail import importing
|
from rattail import importing
|
||||||
|
@ -800,14 +801,13 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
|
||||||
"""
|
"""
|
||||||
Importer for member data from CORE POS API.
|
Importer for member data from CORE POS API.
|
||||||
"""
|
"""
|
||||||
# TODO use this key instead
|
key = 'corepos_card_number'
|
||||||
#key = 'corepos_card_number'
|
|
||||||
key = 'number'
|
|
||||||
supported_fields = [
|
supported_fields = [
|
||||||
'number',
|
'number',
|
||||||
'corepos_account_id',
|
'corepos_account_id',
|
||||||
'corepos_card_number',
|
'corepos_card_number',
|
||||||
'customer_uuid',
|
'customer_uuid',
|
||||||
|
'person_uuid',
|
||||||
'person_first_name',
|
'person_first_name',
|
||||||
'person_last_name',
|
'person_last_name',
|
||||||
'membership_type_number',
|
'membership_type_number',
|
||||||
|
@ -837,9 +837,57 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
|
||||||
model.Customer,
|
model.Customer,
|
||||||
key='number')
|
key='number')
|
||||||
|
|
||||||
|
query = self.session.query(model.Person)\
|
||||||
|
.outerjoin(model.Customer,
|
||||||
|
model.Customer.account_holder_uuid == model.Person.uuid)\
|
||||||
|
.outerjoin(model.CoreCustomer)\
|
||||||
|
.outerjoin(model.Member,
|
||||||
|
model.Member.person_uuid == model.Person.uuid)\
|
||||||
|
.outerjoin(model.CoreMember)\
|
||||||
|
.filter(sa.or_(
|
||||||
|
model.CoreCustomer.corepos_card_number != None,
|
||||||
|
model.CoreMember.corepos_card_number != None))\
|
||||||
|
.options(orm.joinedload(model.Person.customer_accounts)\
|
||||||
|
.joinedload(model.Customer._corepos))
|
||||||
|
def card_number(person, normal):
|
||||||
|
customer = self.app.get_customer(person)
|
||||||
|
if customer and customer.corepos_card_number:
|
||||||
|
return customer.corepos_card_number
|
||||||
|
member = self.app.get_member(person)
|
||||||
|
if member and member.corepos_card_number:
|
||||||
|
return member.corepos_card_number
|
||||||
|
self.people_by_card_number = self.cache_model(model.Person, query=query,
|
||||||
|
key=card_number)
|
||||||
|
|
||||||
def get_host_objects(self):
|
def get_host_objects(self):
|
||||||
return self.get_core_members()
|
return self.get_core_members()
|
||||||
|
|
||||||
|
def get_person(self, card_number):
|
||||||
|
if hasattr(self, 'people_by_card_number'):
|
||||||
|
return self.people_by_card_number.get(card_number)
|
||||||
|
|
||||||
|
model = self.model
|
||||||
|
|
||||||
|
try:
|
||||||
|
return self.session.query(model.Person)\
|
||||||
|
.join(model.Customer,
|
||||||
|
model.Customer.account_holder_uuid == model.Person.uuid)\
|
||||||
|
.join(model.CoreCustomer)\
|
||||||
|
.filter(model.CoreCustomer.corepos_card_number == card_number)\
|
||||||
|
.one()
|
||||||
|
except orm.exc.NoResultFound:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
return self.session.query(model.Person)\
|
||||||
|
.join(model.Member,
|
||||||
|
model.Member.person_uuid == model.Person.uuid)\
|
||||||
|
.join(model.CoreMember)\
|
||||||
|
.filter(model.CoreMember.corepos_card_number == card_number)\
|
||||||
|
.one()
|
||||||
|
except orm.exc.NoResultFound:
|
||||||
|
pass
|
||||||
|
|
||||||
def get_customer_by_number(self, number):
|
def get_customer_by_number(self, number):
|
||||||
if hasattr(self, 'customers_by_number'):
|
if hasattr(self, 'customers_by_number'):
|
||||||
return self.customers_by_number.get(number)
|
return self.customers_by_number.get(number)
|
||||||
|
@ -860,6 +908,7 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
|
||||||
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.get_person(card_number)
|
||||||
|
|
||||||
# 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,
|
||||||
|
@ -902,6 +951,7 @@ class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
|
||||||
'corepos_account_id': int(member['customerAccountID']),
|
'corepos_account_id': int(member['customerAccountID']),
|
||||||
'corepos_card_number': card_number,
|
'corepos_card_number': card_number,
|
||||||
'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_first_name': None,
|
||||||
'person_last_name': None,
|
'person_last_name': None,
|
||||||
'membership_type_number': typeno,
|
'membership_type_number': typeno,
|
||||||
|
|
Loading…
Reference in a new issue