Add 2-way sync for customer contact data, for CORE API <-> Rattail

This commit is contained in:
Lance Edgar 2020-03-17 18:52:08 -05:00
parent 15a99164f2
commit 9dbdb81f07
5 changed files with 80 additions and 10 deletions

View file

@ -94,11 +94,11 @@ class MemberImporter(ToCoreAPI):
# 'idCardUPC',
# 'startDate',
# 'endDate',
# 'addressFirstLine',
# 'addressSecondLine',
# 'city',
# 'state',
# 'zip',
'addressFirstLine',
'addressSecondLine',
'city',
'state',
'zip',
# 'contactAllowed',
# 'contactMethod',
# 'modified',
@ -114,9 +114,9 @@ class MemberImporter(ToCoreAPI):
# 'discount',
'accountHolder',
# 'staff',
# 'phone',
# 'altPhone',
# 'email',
'phone',
'altPhone',
'email',
# 'memberPricingAllowed',
# 'memberCouponsAllowed',
# 'lowIncomeBenefits',

View file

@ -26,6 +26,8 @@ Rattail -> CORE-POS data export
import logging
from sqlalchemy import orm
from rattail import importing
from rattail.db import model
from rattail.db.util import short_session
@ -71,28 +73,61 @@ class MemberImporter(FromRattail, corepos_importing.model.MemberImporter):
'cardNo',
'customerAccountID',
'customers',
'addressFirstLine',
'addressSecondLine',
'city',
'state',
'zip',
]
supported_customer_fields = [
'customerID',
'firstName',
'lastName',
'accountHolder',
'phone',
'altPhone',
'email',
]
def query(self):
query = super(MemberImporter, self).query()
query = query.options(orm.joinedload(model.Customer.addresses))\
.options(orm.joinedload(model.Customer._people)\
.joinedload(model.CustomerPerson.person)\
.joinedload(model.Person.phones))\
.options(orm.joinedload(model.Customer._people)\
.joinedload(model.CustomerPerson.person)\
.joinedload(model.Person.emails))
return query
def normalize_host_object(self, customer):
address = customer.addresses[0] if customer.addresses else None
people = []
for i, person in enumerate(customer.people, 1):
phones = person.phones
phone1 = phones[0] if phones else None
phone2 = phones[1] if len(phones) > 1 else None
email = person.emails[0] if person.emails else None
people.append({
'customerID': str(person.corepos_customer_id),
'firstName': person.first_name,
'lastName': person.last_name,
'accountHolder': i == 1,
'phone': phone1.number if phone1 else '',
'altPhone': phone2.number if phone2 else '',
'email': email.address if email else '',
})
return {
'cardNo': customer.number,
'customerAccountID': customer.id,
'addressFirstLine': address.street if address else '',
'addressSecondLine': address.street2 if address else '',
'city': address.city if address else '',
'state': address.state if address else '',
'zip': address.zipcode if address else '',
'customers': people,
}