#63 Migrate to new API.

This commit is contained in:
Jared Kipe
2018-12-30 09:40:32 -08:00
committed by Jared Kipe
parent 7f56c44d1e
commit ac1a589ce4
2 changed files with 14 additions and 14 deletions

View File

@@ -8,10 +8,10 @@ from logging import getLogger
_logger = getLogger(__name__)
try:
from uszipcode import ZipcodeSearchEngine
from uszipcode import SearchEngine
except ImportError:
_logger.warn('module "uszipcode" cannot be loaded, falling back to Google API')
ZipcodeSearchEngine = None
SearchEngine = None
from odoo import api, fields, models, tools
from odoo.addons.base_geolocalize.models.res_partner import geo_find, geo_query_address
@@ -58,12 +58,12 @@ class FakePartner():
if not hasattr(self, 'date_localization') and self.date_localization:
self.date_localization = 'TODAY!'
# The fast way.
if ZipcodeSearchEngine and self.zip:
with ZipcodeSearchEngine() as search:
if SearchEngine and self.zip:
with SearchEngine() as search:
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
if zipcode and zipcode['Latitude']:
self.partner_latitude = zipcode['Latitude']
self.partner_longitude = zipcode['Longitude']
if zipcode and zipcode.lat:
self.partner_latitude = zipcode.lat
self.partner_longitude = zipcode.lng
return self.date_localization
# The slow way.