Add support for member_type_id
in CORE MemberInfoImporter
also improve support for first, last name sync
This commit is contained in:
parent
4bb03b9cd9
commit
f8de832294
|
@ -31,6 +31,8 @@ CORE-POS model importers (direct DB)
|
||||||
which may exist.
|
which may exist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from corepos.db.office_op import model as corepos, Session as CoreSession
|
from corepos.db.office_op import model as corepos, Session as CoreSession
|
||||||
from corepos.db.office_trans import model as coretrans
|
from corepos.db.office_trans import model as coretrans
|
||||||
|
|
||||||
|
@ -38,11 +40,15 @@ from rattail import importing
|
||||||
from rattail.importing.handlers import ToSQLAlchemyHandler
|
from rattail.importing.handlers import ToSQLAlchemyHandler
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ToCoreHandler(ToSQLAlchemyHandler):
|
class ToCoreHandler(ToSQLAlchemyHandler):
|
||||||
"""
|
"""
|
||||||
Base class for import handlers which target a CORE database on the local side.
|
Base class for import handlers which target a CORE database on the local side.
|
||||||
"""
|
"""
|
||||||
local_title = "CORE"
|
generic_local_title = 'CORE Office (DB "op")'
|
||||||
|
local_title = 'CORE Office (DB "op")'
|
||||||
local_key = 'corepos_db_office_op'
|
local_key = 'corepos_db_office_op'
|
||||||
|
|
||||||
def make_session(self):
|
def make_session(self):
|
||||||
|
@ -152,6 +158,58 @@ class MemberInfoImporter(ToCore):
|
||||||
model_class = corepos.MemberInfo
|
model_class = corepos.MemberInfo
|
||||||
key = 'card_number'
|
key = 'card_number'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_fields(self):
|
||||||
|
fields = list(super(MemberInfoImporter, self).supported_fields)
|
||||||
|
|
||||||
|
fields.append('member_type_id')
|
||||||
|
|
||||||
|
return fields
|
||||||
|
|
||||||
|
def normalize_local_object(self, member):
|
||||||
|
data = super(MemberInfoImporter, self).normalize_local_object(member)
|
||||||
|
|
||||||
|
if 'member_type_id' in self.fields:
|
||||||
|
data['member_type_id'] = None
|
||||||
|
customer = member.customers[0] if member.customers else None
|
||||||
|
if customer:
|
||||||
|
data['member_type_id'] = customer.member_type_id
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def update_object(self, member, host_data, local_data=None, **kwargs):
|
||||||
|
member = super(MemberInfoImporter, self).update_object(
|
||||||
|
member, host_data, local_data=local_data, **kwargs)
|
||||||
|
|
||||||
|
if 'first_name' in self.fields:
|
||||||
|
if member.customers:
|
||||||
|
customer = member.customers[0]
|
||||||
|
first_name = host_data['first_name']
|
||||||
|
if customer.first_name != first_name:
|
||||||
|
customer.first_name = first_name
|
||||||
|
|
||||||
|
if 'last_name' in self.fields:
|
||||||
|
if member.customers:
|
||||||
|
customer = member.customers[0]
|
||||||
|
last_name = host_data['last_name']
|
||||||
|
if customer.last_name != last_name:
|
||||||
|
customer.last_name = last_name
|
||||||
|
|
||||||
|
if 'member_type_id' in self.fields:
|
||||||
|
member_type_id = host_data['member_type_id']
|
||||||
|
for customer in member.customers:
|
||||||
|
if customer.member_type_id != member_type_id:
|
||||||
|
if member_type_id is None:
|
||||||
|
log.warning("will not blank out member_type_id for "
|
||||||
|
"member #%s: %s %s",
|
||||||
|
member.card_number,
|
||||||
|
customer.first_name,
|
||||||
|
customer.last_name)
|
||||||
|
else:
|
||||||
|
customer.member_type_id = member_type_id
|
||||||
|
|
||||||
|
return member
|
||||||
|
|
||||||
|
|
||||||
class MemberDateImporter(ToCore):
|
class MemberDateImporter(ToCore):
|
||||||
model_class = corepos.MemberDate
|
model_class = corepos.MemberDate
|
||||||
|
|
Loading…
Reference in a new issue