[CHERRYPICK 7.0][FIX] crm_partner_assign: Use Google Maps API V3.

Old API is deprecated for 3 years!

bzr revid: chs@openerp.com-20130311141654-o6pniq9mnth00plm
This commit is contained in:
Christophe Simonis 2013-03-11 15:16:54 +01:00
parent f754c89178
commit 80e667a53f
2 changed files with 22 additions and 15 deletions

View File

@ -19,29 +19,36 @@
#
##############################################################################
import urllib
import random
try:
import simplejson as json
except ImportError:
import json # noqa
from openerp.osv import osv
from openerp.osv import fields
import urllib,re
import random, time
from openerp.tools.translate import _
from openerp import tools
def geo_find(addr):
addr = addr.encode('utf8')
regex = '<coordinates>([+-]?[0-9\.]+),([+-]?[0-9\.]+),([+-]?[0-9\.]+)</coordinates>'
url = 'http://maps.google.com/maps/geo?q=' + urllib.quote(addr) + '&output=xml&oe=utf8&sensor=false'
url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
url += urllib.quote(addr.encode('utf8'))
try:
xml = urllib.urlopen(url).read()
result = json.load(urllib.urlopen(url))
except Exception, e:
raise osv.except_osv(_('Network error'),
_('Cannot contact geolocation servers. Please make sure that your internet connection is up and running (%s).') % e)
if result['status'] != 'OK':
return None
if '<error>' in xml:
try:
geo = result['results'][0]['geometry']['location']
return float(geo['lat']), float(geo['lng'])
except (KeyError, ValueError):
return None
result = re.search(regex, xml, re.M|re.I)
if not result:
return None
return float(result.group(2)),float(result.group(1))
def geo_query_address(street=None, zip=None, city=None, state=None, country=None):
if country and ',' in country and (country.endswith(' of') or country.endswith(' of the')):

View File

@ -10,8 +10,8 @@
-
!python {model: res.partner}: |
partner = self.browse(cr, uid, ref('base.res_partner_2'))
assert 50 < partner.partner_latitude < 51 , "Latitude is wrong"
assert 3 < partner.partner_longitude < 5 , "Longitude is wrong"
assert 50 < partner.partner_latitude < 51, "Latitude is wrong: 50 < %s < 51" % partner.partner_latitude
assert 3 < partner.partner_longitude < 5, "Longitude is wrong: 3 < %s < 5" % partner.partner_longitude
-
I assign nearest partner to opportunity.
-
@ -23,8 +23,8 @@
!python {model: crm.lead}: |
lead = self.browse(cr, uid, ref('crm.crm_case_19'))
assert lead.partner_assigned_id.id == ref('base.res_partner_15') , "Opportuniy is not assigned nearest partner"
assert 50 < lead.partner_latitude < 55 , "Latitude is wrong"
assert -5 < lead.partner_longitude < 0, "Longitude is wrong"
assert 50 < lead.partner_latitude < 55, "Latitude is wrong: 50 < %s < 55" % lead.partner_latitude
assert -4 < lead.partner_longitude < -1, "Longitude is wrong: -4 < %s < -1" % lead.partner_longitude
-
I forward this opportunity to its nearest partner.
-