Make some importer logic datasync-friendly

This commit is contained in:
Lance Edgar 2023-06-10 21:58:24 -05:00
parent 43cd63c1f5
commit 87bd1faa58

View file

@ -207,7 +207,7 @@ class CustomerShopperImporter(FromCOREPOSAPI, corepos_importing.model.CustomerSh
super().setup() super().setup()
model = self.model 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.customers_by_card_number = self.app.cache_model(
self.session, self.session,
@ -215,6 +215,13 @@ class CustomerShopperImporter(FromCOREPOSAPI, corepos_importing.model.CustomerSh
key='corepos_card_number', key='corepos_card_number',
query_options=[orm.joinedload(model.Customer._corepos)]) 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): def get_host_objects(self):
# first get all member data from CORE API # 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 # 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), " log.warning("phone_number is too long (%s chars), "
"will truncate to %s chars: %s", "will truncate to %s chars: %s",
len(data['phone_number']), len(data['phone_number']),
self.maxlen_phone_number, maxlen_phone_number,
data['phone_number']) data['phone_number'])
data['phone_number'] = data['phone_number'][:self.maxlen_phone_number] data['phone_number'] = data['phone_number'][:maxlen_phone_number]
if data['phone_number_2'] and len(data['phone_number_2']) > self.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), " log.warning("phone_number_2 is too long (%s chars), "
"will truncate to %s chars: %s", "will truncate to %s chars: %s",
len(data['phone_number_2']), len(data['phone_number_2']),
self.maxlen_phone_number, maxlen_phone_number,
data['phone_number_2']) 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 # swap 1st and 2nd phone numbers if only latter has value
self.prioritize_2(data, 'phone_number') self.prioritize_2(data, 'phone_number')