Make some importer logic datasync-friendly
This commit is contained in:
parent
43cd63c1f5
commit
87bd1faa58
|
@ -207,7 +207,7 @@ class CustomerShopperImporter(FromCOREPOSAPI, corepos_importing.model.CustomerSh
|
|||
super().setup()
|
||||
model = self.model
|
||||
|
||||
self.maxlen_phone_number = self.app.maxlen(model.PhoneNumber.number)
|
||||
self.maxlen_phone_number = self.get_maxlen_phone_number()
|
||||
|
||||
self.customers_by_card_number = self.app.cache_model(
|
||||
self.session,
|
||||
|
@ -215,6 +215,13 @@ class CustomerShopperImporter(FromCOREPOSAPI, corepos_importing.model.CustomerSh
|
|||
key='corepos_card_number',
|
||||
query_options=[orm.joinedload(model.Customer._corepos)])
|
||||
|
||||
def get_maxlen_phone_number(self):
|
||||
if hasattr(self, 'maxlen_phone_number'):
|
||||
return self.maxlen_phone_number
|
||||
|
||||
model = self.model
|
||||
return self.app.maxlen(model.PhoneNumber.number)
|
||||
|
||||
def get_host_objects(self):
|
||||
|
||||
# first get all member data from CORE API
|
||||
|
@ -301,20 +308,21 @@ class CustomerShopperImporter(FromCOREPOSAPI, corepos_importing.model.CustomerSh
|
|||
}
|
||||
|
||||
# truncate phone number data if needed
|
||||
if data['phone_number'] and len(data['phone_number']) > self.maxlen_phone_number:
|
||||
maxlen_phone_number = self.get_maxlen_phone_number()
|
||||
if data['phone_number'] and len(data['phone_number']) > maxlen_phone_number:
|
||||
log.warning("phone_number is too long (%s chars), "
|
||||
"will truncate to %s chars: %s",
|
||||
len(data['phone_number']),
|
||||
self.maxlen_phone_number,
|
||||
maxlen_phone_number,
|
||||
data['phone_number'])
|
||||
data['phone_number'] = data['phone_number'][:self.maxlen_phone_number]
|
||||
if data['phone_number_2'] and len(data['phone_number_2']) > self.maxlen_phone_number:
|
||||
data['phone_number'] = data['phone_number'][:maxlen_phone_number]
|
||||
if data['phone_number_2'] and len(data['phone_number_2']) > maxlen_phone_number:
|
||||
log.warning("phone_number_2 is too long (%s chars), "
|
||||
"will truncate to %s chars: %s",
|
||||
len(data['phone_number_2']),
|
||||
self.maxlen_phone_number,
|
||||
maxlen_phone_number,
|
||||
data['phone_number_2'])
|
||||
data['phone_number_2'] = data['phone_number_2'][:self.maxlen_phone_number]
|
||||
data['phone_number_2'] = data['phone_number_2'][:maxlen_phone_number]
|
||||
|
||||
# swap 1st and 2nd phone numbers if only latter has value
|
||||
self.prioritize_2(data, 'phone_number')
|
||||
|
|
Loading…
Reference in a new issue