From 572d9ab9cc51be1f7cf7ee862d1f555ee1f25389 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sun, 30 Mar 2014 23:50:40 +0200 Subject: [PATCH 01/15] Add module base_location_geonames_import Add support for states (if states are already present in res.country.state). Add POT file and FR translation. Allow to skip entries in the _prepare method. Insist on the fact that the wizard deletes current better zip entries in the module description and in the wizard itself. Better error message when the country code inside the file is wrong. Add a FOR UPDATE NOWAIT at the beginning of the transaction. Remove France-specific code ; moved to new module l10n_fr_base_location_geonames_import on lp:openerp-french-localization Add module base_location_geonames_import Add support for states (if states are already present in res.country.state). Add POT file and FR translation. Allow to skip entries in the _prepare method. Insist on the fact that the wizard deletes current better zip entries in the module description and in the wizard itself. Better error message when the country code inside the file is wrong. Add a FOR UPDATE NOWAIT at the beginning of the transaction. Remove France-specific code ; moved to new module l10n_fr_base_location_geonames_import on lp:openerp-french-localization --- base_location_geonames_import/__init__.py | 23 ++++ base_location_geonames_import/__openerp__.py | 60 +++++++++ .../i18n/base_location_geonames_import.pot | 68 ++++++++++ base_location_geonames_import/i18n/fr.po | 68 ++++++++++ .../wizard/__init__.py | 23 ++++ .../wizard/geonames_import.py | 127 ++++++++++++++++++ .../wizard/geonames_import_view.xml | 44 ++++++ 7 files changed, 413 insertions(+) create mode 100644 base_location_geonames_import/__init__.py create mode 100644 base_location_geonames_import/__openerp__.py create mode 100644 base_location_geonames_import/i18n/base_location_geonames_import.pot create mode 100644 base_location_geonames_import/i18n/fr.po create mode 100644 base_location_geonames_import/wizard/__init__.py create mode 100644 base_location_geonames_import/wizard/geonames_import.py create mode 100644 base_location_geonames_import/wizard/geonames_import_view.xml diff --git a/base_location_geonames_import/__init__.py b/base_location_geonames_import/__init__.py new file mode 100644 index 000000000..b63234221 --- /dev/null +++ b/base_location_geonames_import/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Base Location Geonames Import module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import wizard diff --git a/base_location_geonames_import/__openerp__.py b/base_location_geonames_import/__openerp__.py new file mode 100644 index 000000000..8a91dacc1 --- /dev/null +++ b/base_location_geonames_import/__openerp__.py @@ -0,0 +1,60 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Base Location Geonames Import module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Base Location Geonames Import', + 'version': '0.1', + 'category': 'Extra Tools', + 'license': 'AGPL-3', + 'summary': 'Import better zip entries from Geonames', + 'description': """ +Base Location Geonames Import +============================= + +This module adds a wizard to import better zip entries from Geonames (http://download.geonames.org/export/zip/). + +When you start the wizard, +it will ask you to select a country. Then, for the selected country, +it will delete all the current better zip entries, download the latest version +of the list of cities from geonames.org and create new better zip entries. + +Please contact Alexis de Lattre from Akretion +for any help or question about this module. + + +Contributors +------------ + +- Alexis de Lattre +- Lorenzo Battistini +""", + 'author': "Akretion,Odoo Community Association (OCA)", + 'website': 'http://www.akretion.com', + 'depends': ['base_location'], + 'external_dependencies': {'python': ['requests', 'unicodecsv']}, + 'data': [ + 'wizard/geonames_import_view.xml', + ], + 'installable': True, + 'active': False, +} diff --git a/base_location_geonames_import/i18n/base_location_geonames_import.pot b/base_location_geonames_import/i18n/base_location_geonames_import.pot new file mode 100644 index 000000000..7c5782ea3 --- /dev/null +++ b/base_location_geonames_import/i18n/base_location_geonames_import.pot @@ -0,0 +1,68 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_location_geonames_import +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-11 20:55+0000\n" +"PO-Revision-Date: 2014-04-11 20:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Cancel" +msgstr "" + +#. module: base_location_geonames_import +#: field:better.zip.geonames.import,country_id:0 +msgid "Country" +msgstr "" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:66 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:90 +#, python-format +msgid "Error:" +msgstr "" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "For the country selected above, this wizard will DELETE ALL THE CURRENT BETTER ZIP ENTRIES, download the latest version of the list of cities from geonames.org and create new better zip entries." +msgstr "" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:91 +#, python-format +msgid "Got an error %d when trying to download the file %s." +msgstr "" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Import" +msgstr "" + +#. module: base_location_geonames_import +#: model:ir.model,name:base_location_geonames_import.model_better_zip_geonames_import +msgid "Import Better Zip from Geonames" +msgstr "" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +#: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action +#: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu +msgid "Import Geonames" +msgstr "" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#, python-format +msgid "The country code inside the file (%s) doesn't correspond to the selected country (%s)." +msgstr "" + diff --git a/base_location_geonames_import/i18n/fr.po b/base_location_geonames_import/i18n/fr.po new file mode 100644 index 000000000..699ad7519 --- /dev/null +++ b/base_location_geonames_import/i18n/fr.po @@ -0,0 +1,68 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_location_geonames_import +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-11 20:56+0000\n" +"PO-Revision-Date: 2014-04-11 20:56+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Cancel" +msgstr "Annuler" + +#. module: base_location_geonames_import +#: field:better.zip.geonames.import,country_id:0 +msgid "Country" +msgstr "Pays" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:66 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:90 +#, python-format +msgid "Error:" +msgstr "Erreur :" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "For the country selected above, this wizard will DELETE ALL THE CURRENT BETTER ZIP ENTRIES, download the latest version of the list of cities from geonames.org and create new better zip entries." +msgstr "Pour le pays sélectionné ci-dessus, cet assistant va SUPPRIMER TOUTES LES ENTREES BETTER ZIP, télécharger la dernière version de la liste des villes depuis geonames.org et créer de nouveaux enregistrements better zip." + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:91 +#, python-format +msgid "Got an error %d when trying to download the file %s." +msgstr "Erreur %d reçue suite à la tentative de téléchargement du fichier %s." + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Import" +msgstr "Importer" + +#. module: base_location_geonames_import +#: model:ir.model,name:base_location_geonames_import.model_better_zip_geonames_import +msgid "Import Better Zip from Geonames" +msgstr "Import Better Zip from Geonames" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +#: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action +#: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu +msgid "Import Geonames" +msgstr "Importer Geonames" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#, python-format +msgid "The country code inside the file (%s) doesn't correspond to the selected country (%s)." +msgstr "Le code pays utilisé à l'intérieur du fichier (%s) ne correspond pas au pays sélectionné (%s)." + diff --git a/base_location_geonames_import/wizard/__init__.py b/base_location_geonames_import/wizard/__init__.py new file mode 100644 index 000000000..2c9462e69 --- /dev/null +++ b/base_location_geonames_import/wizard/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Base Location Geonames Import module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import geonames_import diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py new file mode 100644 index 000000000..d93967895 --- /dev/null +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -0,0 +1,127 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Base Location Geonames Import module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm, fields +from openerp.tools.translate import _ +import requests +import tempfile +import StringIO +import unicodecsv +import zipfile +import os +import logging + +logger = logging.getLogger(__name__) + + +class better_zip_geonames_import(orm.TransientModel): + _name = 'better.zip.geonames.import' + _description = 'Import Better Zip from Geonames' + + _columns = { + 'country_id': fields.many2one('res.country', 'Country', required=True), + } + + def _prepare_better_zip( + self, cr, uid, row, country_id, states, context=None): + '''This function is designed to be inherited''' + state_id = False + if states and row[4] and row[4] in states: + state_id = states[row[4].upper()] + vals = { + 'name': row[1], + 'city': row[2], + 'state_id': state_id, + 'country_id': country_id, + } + return vals + + def create_better_zip( + self, cr, uid, row, country_id, country_code, states, + context=None): + bzip_id = False + if row[0] != country_code: + raise orm.except_orm( + _('Error:'), + _("The country code inside the file (%s) doesn't " + "correspond to the selected country (%s).") + % (row[0], country_code)) + logger.debug('ZIP = %s - City = %s' % (row[1], row[2])) + if row[1] and row[2]: + vals = self._prepare_better_zip( + cr, uid, row, country_id, states, context=context) + if vals: + bzip_id = self.pool['res.better.zip'].create( + cr, uid, vals, context=context) + return bzip_id + + def run_import(self, cr, uid, ids, context=None): + assert len(ids) == 1, 'Only one ID for the better zip import wizard' + bzip_obj = self.pool['res.better.zip'] + wizard = self.browse(cr, uid, ids[0], context=context) + country_id = wizard.country_id.id + country_code = wizard.country_id.code.upper() + url = 'http://download.geonames.org/export/zip/%s.zip' % country_code + logger.info('Starting to download %s' % url) + res_request = requests.get(url) + if res_request.status_code != requests.codes.ok: + raise orm.except_orm( + _('Error:'), + _('Got an error %d when trying to download the file %s.') + % (res_request.status_code, url)) + bzip_ids_to_delete = bzip_obj.search( + cr, uid, [('country_id', '=', country_id)], context=context) + if bzip_ids_to_delete: + cr.execute('SELECT id FROM res_better_zip WHERE id in %s ' + 'FOR UPDATE NOWAIT', (tuple(bzip_ids_to_delete), )) + bzip_obj.unlink(cr, uid, bzip_ids_to_delete, context=context) + logger.info( + '%d better zip entries deleted for country %s' + % (len(bzip_ids_to_delete), wizard.country_id.name)) + state_ids = self.pool['res.country.state'].search( + cr, uid, [('country_id', '=', country_id)], context=context) + states = {} + # key = code of the state ; value = ID of the state in OpenERP + if state_ids: + states_r = self.pool['res.country.state'].read( + cr, uid, state_ids, ['code', 'country_id'], context=context) + for state in states_r: + states[state['code'].upper()] = state['id'] + f_geonames = zipfile.ZipFile(StringIO.StringIO(res_request.content)) + tempdir = tempfile.mkdtemp(prefix='openerp') + f_geonames.extract('%s.txt' % country_code, tempdir) + logger.info('The geonames zipfile has been decompressed') + data_file = open(os.path.join(tempdir, '%s.txt' % country_code), 'r') + data_file.seek(0) + logger.info( + 'Starting to create the better zip entries %s state information' + % (states and 'with' or 'without')) + for row in unicodecsv.reader( + data_file, encoding='utf-8', delimiter=' '): + self.create_better_zip( + cr, uid, row, country_id, country_code, states, + context=context) + data_file.close() + logger.info( + 'The wizard to create better zip entries from geonames ' + 'has been successfully completed.') + return True diff --git a/base_location_geonames_import/wizard/geonames_import_view.xml b/base_location_geonames_import/wizard/geonames_import_view.xml new file mode 100644 index 000000000..efd37057d --- /dev/null +++ b/base_location_geonames_import/wizard/geonames_import_view.xml @@ -0,0 +1,44 @@ + + + + + + + + asterisk.server.company + better.zip.geonames.import + +
+ + + +
+
+
+
+
+ + + Import Geonames + better.zip.geonames.import + form + form + new + + + + +
+
From 1b012ec30b6c1beef9f803890a45e092fad65da1 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Sun, 10 Aug 2014 23:07:34 +0200 Subject: [PATCH 02/15] [FIX] WARNING test_8 openerp.models: Cannot execute name_search, no _rec_name defined on better.zip.geonames.import [REF] porting to new api [IMP] removing 'FOR UPDATE NOWAIT' as ROW EXCLUSIVE lock is already acquired by DELETE and INSERT http://www.postgresql.org/docs/9.2/static/explicit-locking.html [REF] select_or_create_state and tests [FIX] __openerp__.py PEP8 [FIX] TypeError: unlink() got multiple values for keyword argument 'context' [IMP] using ir.config_parameter for geonames URL [FIX] missing cr uid --- base_location_geonames_import/__openerp__.py | 14 ++- base_location_geonames_import/test/import.yml | 54 ++++++++++ .../wizard/geonames_import.py | 100 +++++++++--------- 3 files changed, 117 insertions(+), 51 deletions(-) create mode 100644 base_location_geonames_import/test/import.yml diff --git a/base_location_geonames_import/__openerp__.py b/base_location_geonames_import/__openerp__.py index 8a91dacc1..d57674f3e 100644 --- a/base_location_geonames_import/__openerp__.py +++ b/base_location_geonames_import/__openerp__.py @@ -4,6 +4,8 @@ # Base Location Geonames Import module for OpenERP # Copyright (C) 2014 Akretion (http://www.akretion.com) # @author Alexis de Lattre +# Copyright (C) 2014 Agile Business Group (http://www.agilebg.com) +# @author Lorenzo Battistini # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -23,7 +25,7 @@ { 'name': 'Base Location Geonames Import', - 'version': '0.1', + 'version': '8.0.0.2.0', 'category': 'Extra Tools', 'license': 'AGPL-3', 'summary': 'Import better zip entries from Geonames', @@ -31,7 +33,10 @@ Base Location Geonames Import ============================= -This module adds a wizard to import better zip entries from Geonames (http://download.geonames.org/export/zip/). +This module adds a wizard to import better zip entries from Geonames +(http://download.geonames.org/export/zip/). +If want want/need to modify the URL, you can set the 'geonames.url' +system parameter. When you start the wizard, it will ask you to select a country. Then, for the selected country, @@ -54,7 +59,10 @@ Contributors 'external_dependencies': {'python': ['requests', 'unicodecsv']}, 'data': [ 'wizard/geonames_import_view.xml', - ], + ], + 'test': [ + 'test/import.yml' + ], 'installable': True, 'active': False, } diff --git a/base_location_geonames_import/test/import.yml b/base_location_geonames_import/test/import.yml new file mode 100644 index 000000000..66243d24a --- /dev/null +++ b/base_location_geonames_import/test/import.yml @@ -0,0 +1,54 @@ +- + I create the wizard +- + !record {model: better.zip.geonames.import, id: import_wizard_1, view: better_zip_geonames_import_form}: + country_id: base.it +- + I run the import +- + !python {model: better.zip.geonames.import}: | + self.run_import(cr, uid, [ref('import_wizard_1')], context=context) +- + I check the data +- + !python {model: res.better.zip}: | + state_obj = self.pool['res.country.state'] + state_ids = state_obj.search(cr, uid, [ + ('code', '=', 'LG'), + ('country_id', '=', ref('base.it')), + ], context=context) + assert len(state_ids) == 1, "There must be 1 LG" + zip_ids = self.search(cr, uid, [ + ('name', '=', '16017'), + ('city', '=', 'Isola Del Cantone'), + ('state_id', '=', state_ids[0]), + ('country_id', '=', ref('base.it')) + ], context=context) + assert len(zip_ids) == 1, "There must be 1 'Isola Del Cantone'" +- + I create the wizard again +- + !record {model: better.zip.geonames.import, id: import_wizard_2, view: better_zip_geonames_import_form}: + country_id: base.it +- + I run the import again +- + !python {model: better.zip.geonames.import}: | + self.run_import(cr, uid, [ref('import_wizard_2')], context=context) +- + I check the data +- + !python {model: res.better.zip}: | + state_obj = self.pool['res.country.state'] + state_ids = state_obj.search(cr, uid, [ + ('code', '=', 'LG'), + ('country_id', '=', ref('base.it')), + ], context=context) + assert len(state_ids) == 1, "There must be 1 LG" + zip_ids = self.search(cr, uid, [ + ('name', '=', '16017'), + ('city', '=', 'Isola Del Cantone'), + ('state_id', '=', state_ids[0]), + ('country_id', '=', ref('base.it')) + ], context=context) + assert len(zip_ids) == 1, "There must be 1 'Isola Del Cantone'" diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index d93967895..9fb2cf355 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -4,6 +4,8 @@ # Base Location Geonames Import module for OpenERP # Copyright (C) 2014 Akretion (http://www.akretion.com) # @author Alexis de Lattre +# Copyright (C) 2014 Agile Business Group (http://www.agilebg.com) +# @author Lorenzo Battistini # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,8 +22,8 @@ # ############################################################################## -from openerp.osv import orm, fields -from openerp.tools.translate import _ +from openerp import models, fields, api, _ +from openerp.exceptions import Warning import requests import tempfile import StringIO @@ -33,79 +35,84 @@ import logging logger = logging.getLogger(__name__) -class better_zip_geonames_import(orm.TransientModel): +class better_zip_geonames_import(models.TransientModel): _name = 'better.zip.geonames.import' _description = 'Import Better Zip from Geonames' + _rec_name = 'country_id' - _columns = { - 'country_id': fields.many2one('res.country', 'Country', required=True), - } + country_id = fields.Many2one('res.country', 'Country', required=True) - def _prepare_better_zip( - self, cr, uid, row, country_id, states, context=None): - '''This function is designed to be inherited''' - state_id = False - if states and row[4] and row[4] in states: - state_id = states[row[4].upper()] + @api.model + def _prepare_better_zip(self, row, country_id): + state = self.select_or_create_state(row, country_id) vals = { 'name': row[1], 'city': row[2], - 'state_id': state_id, + 'state_id': state.id, 'country_id': country_id, } return vals + @api.model def create_better_zip( - self, cr, uid, row, country_id, country_code, states, - context=None): + self, row, country_id, country_code): bzip_id = False if row[0] != country_code: - raise orm.except_orm( + raise Warning( _('Error:'), _("The country code inside the file (%s) doesn't " "correspond to the selected country (%s).") % (row[0], country_code)) logger.debug('ZIP = %s - City = %s' % (row[1], row[2])) if row[1] and row[2]: - vals = self._prepare_better_zip( - cr, uid, row, country_id, states, context=context) + vals = self._prepare_better_zip(row, country_id) if vals: - bzip_id = self.pool['res.better.zip'].create( - cr, uid, vals, context=context) + bzip_id = self.env['res.better.zip'].create(vals) return bzip_id - def run_import(self, cr, uid, ids, context=None): - assert len(ids) == 1, 'Only one ID for the better zip import wizard' - bzip_obj = self.pool['res.better.zip'] - wizard = self.browse(cr, uid, ids[0], context=context) - country_id = wizard.country_id.id - country_code = wizard.country_id.code.upper() - url = 'http://download.geonames.org/export/zip/%s.zip' % country_code + @api.model + def select_or_create_state( + self, row, country_id, code_row_index=4, name_row_index=3 + ): + states = self.env['res.country.state'].search([ + ('country_id', '=', country_id), + ('code', '=', row[code_row_index]), + ]) + if len(states) > 1: + raise Warning( + _("Too many states with code %s for counrty %s") + % (row[code_row_index], country_id)) + if len(states) == 1: + return states[0] + else: + return self.env['res.country.state'].create({ + 'name': row[name_row_index], + 'code': row[code_row_index], + 'country_id': country_id + }) + + @api.one + def run_import(self): + bzip_obj = self.env['res.better.zip'] + country_id = self.country_id.id + country_code = self.country_id.code.upper() + config_url = self.pool['ir.config_parameter'].get_param( + self._cr, self._uid, 'geonames.url', + default='http://download.geonames.org/export/zip/%s.zip') + url = config_url % country_code logger.info('Starting to download %s' % url) res_request = requests.get(url) if res_request.status_code != requests.codes.ok: - raise orm.except_orm( + raise Warning( _('Error:'), _('Got an error %d when trying to download the file %s.') % (res_request.status_code, url)) - bzip_ids_to_delete = bzip_obj.search( - cr, uid, [('country_id', '=', country_id)], context=context) + bzip_ids_to_delete = bzip_obj.search([('country_id', '=', country_id)]) if bzip_ids_to_delete: - cr.execute('SELECT id FROM res_better_zip WHERE id in %s ' - 'FOR UPDATE NOWAIT', (tuple(bzip_ids_to_delete), )) - bzip_obj.unlink(cr, uid, bzip_ids_to_delete, context=context) + bzip_ids_to_delete.unlink() logger.info( '%d better zip entries deleted for country %s' - % (len(bzip_ids_to_delete), wizard.country_id.name)) - state_ids = self.pool['res.country.state'].search( - cr, uid, [('country_id', '=', country_id)], context=context) - states = {} - # key = code of the state ; value = ID of the state in OpenERP - if state_ids: - states_r = self.pool['res.country.state'].read( - cr, uid, state_ids, ['code', 'country_id'], context=context) - for state in states_r: - states[state['code'].upper()] = state['id'] + % (len(bzip_ids_to_delete), self.country_id.name)) f_geonames = zipfile.ZipFile(StringIO.StringIO(res_request.content)) tempdir = tempfile.mkdtemp(prefix='openerp') f_geonames.extract('%s.txt' % country_code, tempdir) @@ -113,13 +120,10 @@ class better_zip_geonames_import(orm.TransientModel): data_file = open(os.path.join(tempdir, '%s.txt' % country_code), 'r') data_file.seek(0) logger.info( - 'Starting to create the better zip entries %s state information' - % (states and 'with' or 'without')) + 'Starting to create the better zip entries') for row in unicodecsv.reader( data_file, encoding='utf-8', delimiter=' '): - self.create_better_zip( - cr, uid, row, country_id, country_code, states, - context=context) + self.create_better_zip(row, country_id, country_code) data_file.close() logger.info( 'The wizard to create better zip entries from geonames ' From 50e119b6ace45f8789a76b445f5e43d6afbbf68c Mon Sep 17 00:00:00 2001 From: Franco Tampieri Date: Mon, 22 Sep 2014 17:31:05 +0200 Subject: [PATCH 03/15] [Add] Add some italian translation --- base_location_geonames_import/i18n/it.po | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 base_location_geonames_import/i18n/it.po diff --git a/base_location_geonames_import/i18n/it.po b/base_location_geonames_import/i18n/it.po new file mode 100644 index 000000000..cf2a22ed7 --- /dev/null +++ b/base_location_geonames_import/i18n/it.po @@ -0,0 +1,79 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_location_geonames_import +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-11 20:56+0000\n" +"PO-Revision-Date: 2014-09-22 17:30+0100\n" +"Last-Translator: Franco Tampieri \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: it\n" +"X-Generator: Poedit 1.6.9\n" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Cancel" +msgstr "Annulla" + +#. module: base_location_geonames_import +#: field:better.zip.geonames.import,country_id:0 +msgid "Country" +msgstr "Paese" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:66 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:90 +#, python-format +msgid "Error:" +msgstr "Errore:" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "" +"For the country selected above, this wizard will DELETE ALL THE CURRENT " +"BETTER ZIP ENTRIES, download the latest version of the list of cities from " +"geonames.org and create new better zip entries." +msgstr "" +"Per il paese selezionato, questo wizard CANCELLERA' TUTTE LE RIGHE CORRENTI " +"DELL'OGGETTO BETTER ZIP, scaricherà la lista delle città da geonames.org e " +"creerà le nuove righe di better zip." + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:91 +#, python-format +msgid "Got an error %d when trying to download the file %s." +msgstr "Errore %d mentre si stava scaricando il file %s." + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Import" +msgstr "Importa" + +#. module: base_location_geonames_import +#: model:ir.model,name:base_location_geonames_import.model_better_zip_geonames_import +msgid "Import Better Zip from Geonames" +msgstr "Importa Better Zip da Geonames" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +#: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action +#: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu +msgid "Import Geonames" +msgstr "Importa Geonames" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#, python-format +msgid "" +"The country code inside the file (%s) doesn't correspond to the selected " +"country (%s)." +msgstr "" +"Il codice paese all'interno del file (%s) non corrisponde al paese " +"selezionato (%s)." From de4790a8fc0980acb93a119ebab93bc41ceefbb0 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 25 Feb 2015 22:56:47 +0100 Subject: [PATCH 04/15] [IMP] base_location_geonames_import: Several improvements and added hooks * Added Icon. * Improve module description and extracted to README.rst. * Pass country instead of country_id for advance comparisons. * Allow to transform city name. * Some code style. * Do not remove all entries of a country, but only not found. * Include hooks for transforming some things. * Include spanish translation. [FIX] base_location_geonames_import: Use self.env and recordsets --- base_location_geonames_import/README.rst | 61 ++ base_location_geonames_import/__openerp__.py | 30 +- .../i18n/base_location_geonames_import.pot | 4 +- base_location_geonames_import/i18n/es.po | 68 ++ base_location_geonames_import/i18n/fr.po | 4 +- base_location_geonames_import/i18n/it.po | 2 +- .../static/description/icon.png | Bin 0 -> 13202 bytes .../static/description/icon.svg | 782 ++++++++++++++++++ .../wizard/geonames_import.py | 96 ++- .../wizard/geonames_import_view.xml | 68 +- 10 files changed, 1011 insertions(+), 104 deletions(-) create mode 100644 base_location_geonames_import/README.rst create mode 100644 base_location_geonames_import/i18n/es.po create mode 100644 base_location_geonames_import/static/description/icon.png create mode 100644 base_location_geonames_import/static/description/icon.svg diff --git a/base_location_geonames_import/README.rst b/base_location_geonames_import/README.rst new file mode 100644 index 000000000..219404f94 --- /dev/null +++ b/base_location_geonames_import/README.rst @@ -0,0 +1,61 @@ +Base Location Geonames Import +============================= + +This module adds a wizard to import better zip entries from Geonames database. + +Installation +============ +For installing this module, you need these Python libraries: requests and +unicodecsv. + +Configuration +============= + +For seeing the menu, you need to activate *Technical features* option in your +user and to be *Sales manager*. + +If want want/need to modify the default URL +(http://download.geonames.org/export/zip/), you can set the 'geonames.url' +system parameter. + +Usage +===== + +Go to *Sales > Configuration > Address book > Localization > Import from Geonames*, +and click on it to open a wizard. + +When you start the wizard, it will ask you to select a country. Then, for the +selected country, it will delete all the current better zip entries, download +the latest version of the list of cities from geonames.org and create new +better zip entries. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre +* Lorenzo Battistini +* Pedro M. Baeza + +Icon +---- +* http://icon-park.com/icon/location-map-pin-orange3/ +* http://commons.wikimedia.org/wiki/File:View-refresh.svg + + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/base_location_geonames_import/__openerp__.py b/base_location_geonames_import/__openerp__.py index d57674f3e..7ced3b180 100644 --- a/base_location_geonames_import/__openerp__.py +++ b/base_location_geonames_import/__openerp__.py @@ -29,31 +29,11 @@ 'category': 'Extra Tools', 'license': 'AGPL-3', 'summary': 'Import better zip entries from Geonames', - 'description': """ -Base Location Geonames Import -============================= - -This module adds a wizard to import better zip entries from Geonames -(http://download.geonames.org/export/zip/). -If want want/need to modify the URL, you can set the 'geonames.url' -system parameter. - -When you start the wizard, -it will ask you to select a country. Then, for the selected country, -it will delete all the current better zip entries, download the latest version -of the list of cities from geonames.org and create new better zip entries. - -Please contact Alexis de Lattre from Akretion -for any help or question about this module. - - -Contributors ------------- - -- Alexis de Lattre -- Lorenzo Battistini -""", - 'author': "Akretion,Odoo Community Association (OCA)", + 'author': 'Akretion,' + 'Agile Business Group,' + 'Antiun Ingeniería S.L.,' + 'Serv. Tecnol. Avanzados - Pedro M. Baeza,' + 'Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'depends': ['base_location'], 'external_dependencies': {'python': ['requests', 'unicodecsv']}, diff --git a/base_location_geonames_import/i18n/base_location_geonames_import.pot b/base_location_geonames_import/i18n/base_location_geonames_import.pot index 7c5782ea3..8b8fed1c9 100644 --- a/base_location_geonames_import/i18n/base_location_geonames_import.pot +++ b/base_location_geonames_import/i18n/base_location_geonames_import.pot @@ -34,7 +34,7 @@ msgstr "" #. module: base_location_geonames_import #: view:better.zip.geonames.import:0 -msgid "For the country selected above, this wizard will DELETE ALL THE CURRENT BETTER ZIP ENTRIES, download the latest version of the list of cities from geonames.org and create new better zip entries." +msgid "For the country selected above, this wizard will download the latest version of the list of cities from geonames.org, create new location entries if not found already in the system, and DELETE MISSING ENTRIES from new file." msgstr "" #. module: base_location_geonames_import @@ -57,7 +57,7 @@ msgstr "" #: view:better.zip.geonames.import:0 #: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action #: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu -msgid "Import Geonames" +msgid "Import from Geonames" msgstr "" #. module: base_location_geonames_import diff --git a/base_location_geonames_import/i18n/es.po b/base_location_geonames_import/i18n/es.po new file mode 100644 index 000000000..d90390cec --- /dev/null +++ b/base_location_geonames_import/i18n/es.po @@ -0,0 +1,68 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_location_geonames_import +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-11 20:55+0000\n" +"PO-Revision-Date: 2014-04-11 20:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Cancel" +msgstr "Cancelar" + +#. module: base_location_geonames_import +#: field:better.zip.geonames.import,country_id:0 +msgid "Country" +msgstr "País" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:66 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:90 +#, python-format +msgid "Error:" +msgstr "Error:" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "For the country selected above, this wizard will download the latest version of the list of cities from geonames.org, create new location entries if not found already in the system, and DELETE MISSING ENTRIES from new file." +msgstr "Para el país seleccionado arriba, este asistente descargará la última versión de la lista de ciudades de geonames.org, creará nuevas entradas de ubicaciones si no se encuentran ya en el sistema, y BORRARÁ LOS REGISTROS DESAPARECIDOS en el nuevo archivo." + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:91 +#, python-format +msgid "Got an error %d when trying to download the file %s." +msgstr "Se obtuvo un error %d cuando se descargaba el archivo %s." + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +msgid "Import" +msgstr "Importar" + +#. module: base_location_geonames_import +#: model:ir.model,name:base_location_geonames_import.model_better_zip_geonames_import +msgid "Import Better Zip from Geonames" +msgstr "Importar ubicaciones de Geonames" + +#. module: base_location_geonames_import +#: view:better.zip.geonames.import:0 +#: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action +#: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu +msgid "Import from Geonames" +msgstr "Importar de GeoNames" + +#. module: base_location_geonames_import +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#, python-format +msgid "The country code inside the file (%s) doesn't correspond to the selected country (%s)." +msgstr "El código de país dentro del archivo (%s) no se corresponde con el país seleccionado (%s)." + diff --git a/base_location_geonames_import/i18n/fr.po b/base_location_geonames_import/i18n/fr.po index 699ad7519..83d187777 100644 --- a/base_location_geonames_import/i18n/fr.po +++ b/base_location_geonames_import/i18n/fr.po @@ -57,8 +57,8 @@ msgstr "Import Better Zip from Geonames" #: view:better.zip.geonames.import:0 #: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action #: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu -msgid "Import Geonames" -msgstr "Importer Geonames" +msgid "Import from Geonames" +msgstr "Importer de Geonames" #. module: base_location_geonames_import #: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 diff --git a/base_location_geonames_import/i18n/it.po b/base_location_geonames_import/i18n/it.po index cf2a22ed7..63e061099 100644 --- a/base_location_geonames_import/i18n/it.po +++ b/base_location_geonames_import/i18n/it.po @@ -66,7 +66,7 @@ msgstr "Importa Better Zip da Geonames" #: model:ir.actions.act_window,name:base_location_geonames_import.better_zip_geonames_import_action #: model:ir.ui.menu,name:base_location_geonames_import.better_zip_geonames_import_menu msgid "Import Geonames" -msgstr "Importa Geonames" +msgstr "Importa da Geonames" #. module: base_location_geonames_import #: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 diff --git a/base_location_geonames_import/static/description/icon.png b/base_location_geonames_import/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9b0eb86e37a8f01b63254f10c8e0f6cf670e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abXjhqY>Yzv@#d|F zMBj%3YEAgu0Xz~l@u8?!MI5%MntNEfIHfshhJ?0;9GZ>>_tI8Iy^SE}f9kx4A8Lwe zlz&MqA1%)`;WU>v@9&>>-$i|Km_!1I5A|LwGouz4z*ZWgs-Lj+%H}toTo$s5%Ch^V zk)}v+DG8`iKWF3Nv}U^`$r{602OxR|{5`&Rjb40{Dp*kV0`u7$?xZWLY}MadLwUO8 zwTs*@hVKyP=(#=Zjzg3ld)+}!oCH3k^B1{T>>IcW59G9TQ3=yr1kWdj2*$t69dx=` zx}8LHM9eYG$xE2qx@>t&{uqNaZ!Bk+kG-Kt&EBG);S^`AS8K%*M15k*Pp7bUK=r~_@KD` z*O|S%_CxStbNTYjbHf@MSARm)wE5l%8Pv*2Y#$dANapZ9#i4B8LKJeV^=FC}OEmfb zdR++&%jkDicf+v5Pl3HpozYhfDCQt)BZZ+gf4h^gKw6kkP>)(_{fU<-P*Df5|v5!>M@)F6%An-trvx9^_4ry4Sy4 zner12+KAlKZ-p)50myjw!}I&E>p*TlqfVS783-gWyu%AdH;wgXqRc_xc1_;tSi7!2=A2*|G|=7MI6%BYj;>N+A8a1#2XJhfVxt0Y9uulf7u2G?F5_sB@G zGPw8z84pPRez;ZMsM~o9*+ig)R3izpQ}DPjPqoRSS>hg)nN*&WpeOL>UIlke#L6a| za|BcA?a$VoVB@(OccH@%2c+-Kc)vuwJxI&WZ0Ulo7ls8v-uIbpVYojgg(B|g%YcFp z%;RkPCh=PNY1~Ikz0o1PCs%p?eLI1TGq3#08e(334?1Szz)MSf!+WTz>uUe%R=#Vu}WE2onH*s4j}DWA7- z`{ghd<&Z%Q00zW{-Blv;Jo^Ny3hTTQ9f}F;duQHL)bu~M$;;GP#%!cXzpfZh{{x4& XC#<&@dn+O5{Qy-(Erl96n~47biYxHo literal 0 HcmV?d00001 diff --git a/base_location_geonames_import/static/description/icon.svg b/base_location_geonames_import/static/description/icon.svg new file mode 100644 index 000000000..60d8003eb --- /dev/null +++ b/base_location_geonames_import/static/description/icon.svg @@ -0,0 +1,782 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index 9fb2cf355..a3535be8f 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -27,15 +27,19 @@ from openerp.exceptions import Warning import requests import tempfile import StringIO -import unicodecsv import zipfile import os import logging +try: + import unicodecsv +except ImportError: + unicodecsv = None + logger = logging.getLogger(__name__) -class better_zip_geonames_import(models.TransientModel): +class BetterZipGeonamesImport(models.TransientModel): _name = 'better.zip.geonames.import' _description = 'Import Better Zip from Geonames' _rec_name = 'country_id' @@ -43,88 +47,106 @@ class better_zip_geonames_import(models.TransientModel): country_id = fields.Many2one('res.country', 'Country', required=True) @api.model - def _prepare_better_zip(self, row, country_id): - state = self.select_or_create_state(row, country_id) + def transform_city_name(self, city, country): + """Override it for transforming city name (if needed) + :param city: Original city name + :param country: Country record + :return: Transformed city name + """ + return city + + @api.model + def _domain_search_better_zip(self, row, country): + return [('name', '=', row[1]), + ('city', '=', self.transform_city_name(row[2], country)), + ('country_id', '=', country.id)] + + @api.model + def _prepare_better_zip(self, row, country): + state = self.select_or_create_state(row, country) vals = { 'name': row[1], - 'city': row[2], + 'city': self.transform_city_name(row[2], country), 'state_id': state.id, - 'country_id': country_id, + 'country_id': country.id, } return vals @api.model - def create_better_zip( - self, row, country_id, country_code): - bzip_id = False - if row[0] != country_code: + def create_better_zip(self, row, country): + if row[0] != country.code: raise Warning( - _('Error:'), _("The country code inside the file (%s) doesn't " "correspond to the selected country (%s).") - % (row[0], country_code)) + % (row[0], country.code)) logger.debug('ZIP = %s - City = %s' % (row[1], row[2])) if row[1] and row[2]: - vals = self._prepare_better_zip(row, country_id) - if vals: - bzip_id = self.env['res.better.zip'].create(vals) - return bzip_id + zip_model = self.env['res.better.zip'] + zips = zip_model.search(self._domain_search_better_zip( + row, country)) + if zips: + return zips[0] + else: + vals = self._prepare_better_zip(row, country) + if vals: + return zip_model.create(vals) + else: + return False @api.model def select_or_create_state( - self, row, country_id, code_row_index=4, name_row_index=3 - ): + self, row, country, code_row_index=4, name_row_index=3): states = self.env['res.country.state'].search([ - ('country_id', '=', country_id), + ('country_id', '=', country.id), ('code', '=', row[code_row_index]), ]) if len(states) > 1: raise Warning( - _("Too many states with code %s for counrty %s") - % (row[code_row_index], country_id)) + _("Too many states with code %s for country %s") + % (row[code_row_index], country.code)) if len(states) == 1: return states[0] else: return self.env['res.country.state'].create({ 'name': row[name_row_index], 'code': row[code_row_index], - 'country_id': country_id + 'country_id': country.id }) @api.one def run_import(self): - bzip_obj = self.env['res.better.zip'] - country_id = self.country_id.id - country_code = self.country_id.code.upper() - config_url = self.pool['ir.config_parameter'].get_param( - self._cr, self._uid, 'geonames.url', + zip_model = self.env['res.better.zip'] + country_code = self.country_id.code + config_url = self.env['ir.config_parameter'].get_param( + 'geonames.url', default='http://download.geonames.org/export/zip/%s.zip') url = config_url % country_code logger.info('Starting to download %s' % url) res_request = requests.get(url) if res_request.status_code != requests.codes.ok: raise Warning( - _('Error:'), _('Got an error %d when trying to download the file %s.') % (res_request.status_code, url)) - bzip_ids_to_delete = bzip_obj.search([('country_id', '=', country_id)]) - if bzip_ids_to_delete: - bzip_ids_to_delete.unlink() - logger.info( - '%d better zip entries deleted for country %s' - % (len(bzip_ids_to_delete), self.country_id.name)) + # Store current record list + zips_to_delete = zip_model.search( + [('country_id', '=', self.country_id.id)]) f_geonames = zipfile.ZipFile(StringIO.StringIO(res_request.content)) tempdir = tempfile.mkdtemp(prefix='openerp') f_geonames.extract('%s.txt' % country_code, tempdir) logger.info('The geonames zipfile has been decompressed') data_file = open(os.path.join(tempdir, '%s.txt' % country_code), 'r') data_file.seek(0) - logger.info( - 'Starting to create the better zip entries') + logger.info('Starting to create the better zip entries') for row in unicodecsv.reader( data_file, encoding='utf-8', delimiter=' '): - self.create_better_zip(row, country_id, country_code) + zip = self.create_better_zip(row, self.country_id) + if zip in zips_to_delete: + zips_to_delete -= zip data_file.close() + if zips_to_delete: + zips_to_delete.unlink() + logger.info('%d better zip entries deleted for country %s' % + (len(zips_to_delete), self.country_id.name)) logger.info( 'The wizard to create better zip entries from geonames ' 'has been successfully completed.') diff --git a/base_location_geonames_import/wizard/geonames_import_view.xml b/base_location_geonames_import/wizard/geonames_import_view.xml index efd37057d..ce535f799 100644 --- a/base_location_geonames_import/wizard/geonames_import_view.xml +++ b/base_location_geonames_import/wizard/geonames_import_view.xml @@ -1,44 +1,38 @@ - - - + - - asterisk.server.company - better.zip.geonames.import - -
- - - -
-
-
-
-
+ + asterisk.server.company + better.zip.geonames.import + +
+ + + +
+
+
+
+
- - Import Geonames - better.zip.geonames.import - form - form - new - + + Import from Geonames + better.zip.geonames.import + form + form + new + - + -
+
From 11ec70625ed8cc40cddbd6d1b050a8ba2657a6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Mon, 21 Dec 2015 17:51:00 -0300 Subject: [PATCH 05/15] Added option to convert retreived names to Title Case. OCA requirements --- base_location_geonames_import/__openerp__.py | 4 ++-- base_location_geonames_import/wizard/geonames_import.py | 9 ++++++++- .../wizard/geonames_import_view.xml | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/base_location_geonames_import/__openerp__.py b/base_location_geonames_import/__openerp__.py index 7ced3b180..2a1c3a180 100644 --- a/base_location_geonames_import/__openerp__.py +++ b/base_location_geonames_import/__openerp__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Base Location Geonames Import module for OpenERP @@ -25,7 +25,7 @@ { 'name': 'Base Location Geonames Import', - 'version': '8.0.0.2.0', + 'version': '8.0.0.3.0', 'category': 'Extra Tools', 'license': 'AGPL-3', 'summary': 'Import better zip entries from Geonames', diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index a3535be8f..f04881c60 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Base Location Geonames Import module for OpenERP @@ -45,6 +45,10 @@ class BetterZipGeonamesImport(models.TransientModel): _rec_name = 'country_id' country_id = fields.Many2one('res.country', 'Country', required=True) + title_case = fields.Boolean( + string='Title Case', + help='Converts retreived city and state names to Title Case.', + ) @api.model def transform_city_name(self, city, country): @@ -80,6 +84,9 @@ class BetterZipGeonamesImport(models.TransientModel): "correspond to the selected country (%s).") % (row[0], country.code)) logger.debug('ZIP = %s - City = %s' % (row[1], row[2])) + if (self.title_case): + row[2] = row[2].title() + row[3] = row[3].title() if row[1] and row[2]: zip_model = self.env['res.better.zip'] zips = zip_model.search(self._domain_search_better_zip( diff --git a/base_location_geonames_import/wizard/geonames_import_view.xml b/base_location_geonames_import/wizard/geonames_import_view.xml index ce535f799..ea7a102a6 100644 --- a/base_location_geonames_import/wizard/geonames_import_view.xml +++ b/base_location_geonames_import/wizard/geonames_import_view.xml @@ -12,6 +12,9 @@