[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:
parent
f754c89178
commit
80e667a53f
|
@ -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 osv
|
||||||
from openerp.osv import fields
|
from openerp.osv import fields
|
||||||
import urllib,re
|
|
||||||
import random, time
|
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
|
|
||||||
def geo_find(addr):
|
def geo_find(addr):
|
||||||
addr = addr.encode('utf8')
|
url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
|
||||||
regex = '<coordinates>([+-]?[0-9\.]+),([+-]?[0-9\.]+),([+-]?[0-9\.]+)</coordinates>'
|
url += urllib.quote(addr.encode('utf8'))
|
||||||
url = 'http://maps.google.com/maps/geo?q=' + urllib.quote(addr) + '&output=xml&oe=utf8&sensor=false'
|
|
||||||
try:
|
try:
|
||||||
xml = urllib.urlopen(url).read()
|
result = json.load(urllib.urlopen(url))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise osv.except_osv(_('Network error'),
|
raise osv.except_osv(_('Network error'),
|
||||||
_('Cannot contact geolocation servers. Please make sure that your internet connection is up and running (%s).') % e)
|
_('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
|
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):
|
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')):
|
if country and ',' in country and (country.endswith(' of') or country.endswith(' of the')):
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
-
|
-
|
||||||
!python {model: res.partner}: |
|
!python {model: res.partner}: |
|
||||||
partner = self.browse(cr, uid, ref('base.res_partner_2'))
|
partner = self.browse(cr, uid, ref('base.res_partner_2'))
|
||||||
assert 50 < partner.partner_latitude < 51 , "Latitude 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"
|
assert 3 < partner.partner_longitude < 5, "Longitude is wrong: 3 < %s < 5" % partner.partner_longitude
|
||||||
-
|
-
|
||||||
I assign nearest partner to opportunity.
|
I assign nearest partner to opportunity.
|
||||||
-
|
-
|
||||||
|
@ -23,8 +23,8 @@
|
||||||
!python {model: crm.lead}: |
|
!python {model: crm.lead}: |
|
||||||
lead = self.browse(cr, uid, ref('crm.crm_case_19'))
|
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 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 50 < lead.partner_latitude < 55, "Latitude is wrong: 50 < %s < 55" % lead.partner_latitude
|
||||||
assert -5 < lead.partner_longitude < 0, "Longitude is wrong"
|
assert -4 < lead.partner_longitude < -1, "Longitude is wrong: -4 < %s < -1" % lead.partner_longitude
|
||||||
-
|
-
|
||||||
I forward this opportunity to its nearest partner.
|
I forward this opportunity to its nearest partner.
|
||||||
-
|
-
|
||||||
|
|
Loading…
Reference in New Issue