mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
FIX sale_planner It is possible that the 'fall back' core geo_localize can raise an index error
This commit is contained in:
@@ -13,17 +13,20 @@ class Partner(models.Model):
|
||||
def geo_localize(self):
|
||||
# We need country names in English below
|
||||
for partner in self.with_context(lang='en_US'):
|
||||
if SearchEngine and partner.zip:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||
if zipcode and zipcode.lat:
|
||||
partner.write({
|
||||
'partner_latitude': zipcode.lat,
|
||||
'partner_longitude': zipcode.lng,
|
||||
'date_localization': fields.Date.context_today(partner),
|
||||
})
|
||||
else:
|
||||
super(Partner, partner).geo_localize()
|
||||
else:
|
||||
super(Partner, partner).geo_localize()
|
||||
try:
|
||||
if SearchEngine and partner.zip:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||
if zipcode and zipcode.lat:
|
||||
partner.write({
|
||||
'partner_latitude': zipcode.lat,
|
||||
'partner_longitude': zipcode.lng,
|
||||
'date_localization': fields.Date.context_today(partner),
|
||||
})
|
||||
else:
|
||||
super(Partner, partner).geo_localize()
|
||||
else:
|
||||
super(Partner, partner).geo_localize()
|
||||
except:
|
||||
pass
|
||||
return True
|
||||
|
||||
@@ -58,28 +58,30 @@ class FakePartner():
|
||||
|
||||
@property
|
||||
def date_localization(self):
|
||||
if not hasattr(self, 'date_localization') and self.date_localization:
|
||||
self.date_localization = 'TODAY!'
|
||||
# The fast way.
|
||||
if SearchEngine and self.zip:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||
if zipcode and zipcode.lat:
|
||||
self.partner_latitude = zipcode.lat
|
||||
self.partner_longitude = zipcode.lng
|
||||
return self.date_localization
|
||||
if not self._date_localization:
|
||||
try:
|
||||
self._date_localization = 'TODAY!'
|
||||
# The fast way.
|
||||
if SearchEngine and self.zip:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||
if zipcode and zipcode.lat:
|
||||
self.partner_latitude = zipcode.lat
|
||||
self.partner_longitude = zipcode.lng
|
||||
return self._date_localization
|
||||
|
||||
# The slow way.
|
||||
result = geo_find(geo_query_address(
|
||||
city=self.city,
|
||||
state=self.state_id.name,
|
||||
country=self.country_id.name,
|
||||
))
|
||||
if result:
|
||||
self.partner_latitude = result[0]
|
||||
self.partner_longitude = result[1]
|
||||
|
||||
return self.date_localization
|
||||
# The slow way.
|
||||
result = geo_find(geo_query_address(
|
||||
city=self.city,
|
||||
state=self.state_id.name,
|
||||
country=self.country_id.name,
|
||||
))
|
||||
if result:
|
||||
self.partner_latitude = result[0]
|
||||
self.partner_longitude = result[1]
|
||||
except:
|
||||
self._date_localization = 'ERROR'
|
||||
return self._date_localization
|
||||
|
||||
def __getattr__(self, item):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user