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):
|
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'):
|
||||||
if SearchEngine and partner.zip:
|
try:
|
||||||
with SearchEngine() as search:
|
if SearchEngine and partner.zip:
|
||||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
with SearchEngine() as search:
|
||||||
if zipcode and zipcode.lat:
|
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||||
partner.write({
|
if zipcode and zipcode.lat:
|
||||||
'partner_latitude': zipcode.lat,
|
partner.write({
|
||||||
'partner_longitude': zipcode.lng,
|
'partner_latitude': zipcode.lat,
|
||||||
'date_localization': fields.Date.context_today(partner),
|
'partner_longitude': zipcode.lng,
|
||||||
})
|
'date_localization': fields.Date.context_today(partner),
|
||||||
else:
|
})
|
||||||
super(Partner, partner).geo_localize()
|
else:
|
||||||
else:
|
super(Partner, partner).geo_localize()
|
||||||
super(Partner, partner).geo_localize()
|
else:
|
||||||
|
super(Partner, partner).geo_localize()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -58,28 +58,30 @@ class FakePartner():
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def date_localization(self):
|
def date_localization(self):
|
||||||
if not hasattr(self, 'date_localization') and self.date_localization:
|
if not self._date_localization:
|
||||||
self.date_localization = 'TODAY!'
|
try:
|
||||||
# The fast way.
|
self._date_localization = 'TODAY!'
|
||||||
if SearchEngine and self.zip:
|
# The fast way.
|
||||||
with SearchEngine() as search:
|
if SearchEngine and self.zip:
|
||||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
with SearchEngine() as search:
|
||||||
if zipcode and zipcode.lat:
|
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||||
self.partner_latitude = zipcode.lat
|
if zipcode and zipcode.lat:
|
||||||
self.partner_longitude = zipcode.lng
|
self.partner_latitude = zipcode.lat
|
||||||
return self.date_localization
|
self.partner_longitude = zipcode.lng
|
||||||
|
return self._date_localization
|
||||||
|
|
||||||
# The slow way.
|
# The slow way.
|
||||||
result = geo_find(geo_query_address(
|
result = geo_find(geo_query_address(
|
||||||
city=self.city,
|
city=self.city,
|
||||||
state=self.state_id.name,
|
state=self.state_id.name,
|
||||||
country=self.country_id.name,
|
country=self.country_id.name,
|
||||||
))
|
))
|
||||||
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:
|
||||||
return self.date_localization
|
self._date_localization = 'ERROR'
|
||||||
|
return self._date_localization
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user