From 0153b595bedfac035775c5907db217a44ae18636 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 26 Aug 2018 11:36:22 -0700 Subject: [PATCH 1/3] Initial commit of `l10n_us_partner_zipcode` for 11.0 --- l10n_us_partner_zipcode/__init__.py | 1 + l10n_us_partner_zipcode/__manifest__.py | 37 +++++++++++++++++++++++ l10n_us_partner_zipcode/res_partner.py | 39 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 l10n_us_partner_zipcode/__init__.py create mode 100644 l10n_us_partner_zipcode/__manifest__.py create mode 100644 l10n_us_partner_zipcode/res_partner.py diff --git a/l10n_us_partner_zipcode/__init__.py b/l10n_us_partner_zipcode/__init__.py new file mode 100644 index 00000000..91fed54d --- /dev/null +++ b/l10n_us_partner_zipcode/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/l10n_us_partner_zipcode/__manifest__.py b/l10n_us_partner_zipcode/__manifest__.py new file mode 100644 index 00000000..d2461c7d --- /dev/null +++ b/l10n_us_partner_zipcode/__manifest__.py @@ -0,0 +1,37 @@ +{ + 'name': 'US ZIP Code to City/State', + 'summary': 'Determines the City and State from a provided ZIP code.', + 'version': '11.0.1.0.0', + 'author': "Hibou Corp.", + 'category': 'Localization', + 'license': 'AGPL-3', + 'complexity': 'easy', + 'images': [], + 'website': "https://hibou.io", + 'description': """ +US ZIP Code to City/State +========================= + +Determines the City and State from a provided ZIP code. Requires the `uszipcode` python package. + +Does not require `base_geolocalize`, but will fill the related fields if possible. + + +Contributors +------------ + +* Jared Kipe + +""", + 'depends': [ + 'base', + ], + 'external_dependencies': { + 'python': ['uszipcode'] + }, + 'demo': [], + 'data': [ + ], + 'auto_install': False, + 'installable': True, +} diff --git a/l10n_us_partner_zipcode/res_partner.py b/l10n_us_partner_zipcode/res_partner.py new file mode 100644 index 00000000..d21924d7 --- /dev/null +++ b/l10n_us_partner_zipcode/res_partner.py @@ -0,0 +1,39 @@ +import logging + +_logger = logging.getLogger(__name__) + +try: + from uszipcode import ZipcodeSearchEngine +except ImportError: + _logger.warn('module "uszipcode" cannot be loaded, you will be unable to detect Cities and States by ZIP') + ZipcodeSearchEngine = None + +from odoo import api, fields, models + + +class Partner(models.Model): + _inherit = 'res.partner' + + @api.onchange('zip') + def _zip_to_city_state(self): + if ZipcodeSearchEngine 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: + zipcode = search.by_zipcode(self.zip) + if zipcode: + if not self.country_id: + self.country_id = country_us + + self.city = zipcode['City'] + self.state_id = state_obj.search([ + ('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.date_localization = fields.Date.context_today(self) + return {} From 39d90c281b9c0535544efd12bf65bf9fc247df0a Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 30 Dec 2018 09:40:32 -0800 Subject: [PATCH 2/3] #63 Migrate to new API. --- l10n_us_partner_zipcode/res_partner.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/l10n_us_partner_zipcode/res_partner.py b/l10n_us_partner_zipcode/res_partner.py index d21924d7..f209168a 100644 --- a/l10n_us_partner_zipcode/res_partner.py +++ b/l10n_us_partner_zipcode/res_partner.py @@ -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 {} From 5db0df076ee4bb65379eaf545a282e30036274ff Mon Sep 17 00:00:00 2001 From: Bhoomi Date: Thu, 19 Sep 2019 19:21:46 -0400 Subject: [PATCH 3/3] MIG `l10n_us_partner_zipcode` For Odoo 12.0 --- l10n_us_partner_zipcode/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_us_partner_zipcode/__manifest__.py b/l10n_us_partner_zipcode/__manifest__.py index d2461c7d..584eac06 100644 --- a/l10n_us_partner_zipcode/__manifest__.py +++ b/l10n_us_partner_zipcode/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'US ZIP Code to City/State', 'summary': 'Determines the City and State from a provided ZIP code.', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'author': "Hibou Corp.", 'category': 'Localization', 'license': 'AGPL-3',