mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
#63 Migrate to new API.
This commit is contained in:
@@ -3,10 +3,10 @@ import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from uszipcode import ZipcodeSearchEngine
|
||||
from uszipcode import SearchEngine
|
||||
except ImportError:
|
||||
_logger.warn('module "uszipcode" cannot be loaded, you will be unable to detect Cities and States by ZIP')
|
||||
ZipcodeSearchEngine = None
|
||||
SearchEngine = None
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
@@ -16,24 +16,24 @@ class Partner(models.Model):
|
||||
|
||||
@api.onchange('zip')
|
||||
def _zip_to_city_state(self):
|
||||
if ZipcodeSearchEngine and self.zip and not self.city:
|
||||
if SearchEngine and self.zip and not self.city:
|
||||
country_us = self.env['res.country'].search([('code', '=', 'US')], limit=1)
|
||||
state_obj = self.env['res.country.state']
|
||||
if not self.country_id or self.country_id.id == country_us.id:
|
||||
with ZipcodeSearchEngine() as search:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(self.zip)
|
||||
if zipcode:
|
||||
if not self.country_id:
|
||||
self.country_id = country_us
|
||||
|
||||
self.city = zipcode['City']
|
||||
self.city = zipcode.city
|
||||
self.state_id = state_obj.search([
|
||||
('code', '=', zipcode['State']),
|
||||
('code', '=', zipcode.state),
|
||||
('country_id', '=', country_us.id),
|
||||
], limit=1)
|
||||
|
||||
if hasattr(self, 'partner_latitude') and not self.partner_latitude:
|
||||
self.partner_latitude = zipcode['Latitude']
|
||||
self.partner_longitude = zipcode['Longitude']
|
||||
self.partner_latitude = zipcode.lat
|
||||
self.partner_longitude = zipcode.lng
|
||||
self.date_localization = fields.Date.context_today(self)
|
||||
return {}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
try:
|
||||
from uszipcode import ZipcodeSearchEngine
|
||||
from uszipcode import SearchEngine
|
||||
except ImportError:
|
||||
ZipcodeSearchEngine = None
|
||||
SearchEngine = None
|
||||
|
||||
|
||||
class Partner(models.Model):
|
||||
@@ -13,13 +13,13 @@ class Partner(models.Model):
|
||||
def geo_localize(self):
|
||||
# We need country names in English below
|
||||
for partner in self.with_context(lang='en_US'):
|
||||
if ZipcodeSearchEngine and partner.zip:
|
||||
with ZipcodeSearchEngine() as search:
|
||||
if SearchEngine and partner.zip:
|
||||
with SearchEngine() as search:
|
||||
zipcode = search.by_zipcode(str(self.zip).split('-')[0])
|
||||
if zipcode and zipcode['Latitude']:
|
||||
if zipcode and zipcode.lat:
|
||||
partner.write({
|
||||
'partner_latitude': zipcode['Latitude'],
|
||||
'partner_longitude': zipcode['Longitude'],
|
||||
'partner_latitude': zipcode.lat,
|
||||
'partner_longitude': zipcode.lng,
|
||||
'date_localization': fields.Date.context_today(partner),
|
||||
})
|
||||
else:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user