FIX sale_planner It is possible that the 'fall back' core geo_localize can raise an index error

This commit is contained in:
Jared Kipe
2019-08-06 16:11:36 -07:00
parent c54a601d21
commit 0d7bfda5df
2 changed files with 37 additions and 32 deletions

View File

@@ -13,6 +13,7 @@ class Partner(models.Model):
def geo_localize(self): def geo_localize(self):
# We need country names in English below # We need country names in English below
for partner in self.with_context(lang='en_US'): for partner in self.with_context(lang='en_US'):
try:
if SearchEngine and partner.zip: if SearchEngine and partner.zip:
with SearchEngine() as search: with SearchEngine() as search:
zipcode = search.by_zipcode(str(self.zip).split('-')[0]) zipcode = search.by_zipcode(str(self.zip).split('-')[0])
@@ -26,4 +27,6 @@ class Partner(models.Model):
super(Partner, partner).geo_localize() super(Partner, partner).geo_localize()
else: else:
super(Partner, partner).geo_localize() super(Partner, partner).geo_localize()
except:
pass
return True return True

View File

@@ -59,6 +59,7 @@ class FakePartner():
@property @property
def date_localization(self): def date_localization(self):
if not self._date_localization: if not self._date_localization:
try:
self._date_localization = 'TODAY!' self._date_localization = 'TODAY!'
# The fast way. # The fast way.
if SearchEngine and self.zip: if SearchEngine and self.zip:
@@ -78,7 +79,8 @@ class FakePartner():
if result: if result:
self.partner_latitude = result[0] self.partner_latitude = result[0]
self.partner_longitude = result[1] self.partner_longitude = result[1]
except:
self._date_localization = 'ERROR'
return self._date_localization return self._date_localization
def __getattr__(self, item): def __getattr__(self, item):