[FIX] base_geolocalize, website_crm_partner_assign: geolocalize fallback on city

If the street cannot be localized, we retry with only the city.
This commit is contained in:
Jeremy Kersten
2016-12-07 16:03:29 +01:00
parent d3ea014f56
commit 7d968116bd
2 changed files with 16 additions and 0 deletions
@@ -15,6 +15,7 @@ def geo_find(addr):
result = json.load(urllib.urlopen(url))
except Exception as e:
raise UserError(_('Cannot contact geolocation servers. Please make sure that your Internet connection is up and running (%s).') % e)
if result['status'] != 'OK':
return None
@@ -52,6 +53,13 @@ class ResPartner(models.Model):
city=partner.city,
state=partner.state_id.name,
country=partner.country_id.name))
if result is None:
result = geo_find(geo_query_address(
city=partner.city,
state=partner.state_id.name,
country=partner.country_id.name
))
if result:
partner.write({
'partner_latitude': result[0],
@@ -93,6 +93,14 @@ class CrmLead(models.Model):
city=lead.city,
state=lead.state_id.name,
country=lead.country_id.name))
if result is None:
result = geo_find(geo_query_address(
city=lead.city,
state=lead.state_id.name,
country=lead.country_id.name
))
if result:
lead.write({
'partner_latitude': result[0],