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..d45e4e250 100644 --- a/base_location_geonames_import/i18n/base_location_geonames_import.pot +++ b/base_location_geonames_import/i18n/base_location_geonames_import.pot @@ -6,8 +6,8 @@ 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" +"POT-Creation-Date: 2014-04-07 15:00+0000\n" +"PO-Revision-Date: 2014-04-07 15:00+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -26,19 +26,19 @@ 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 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:64 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:87 #, 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." +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 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:88 #, python-format msgid "Got an error %d when trying to download the file %s." msgstr "" @@ -61,8 +61,8 @@ msgid "Import Geonames" msgstr "" #. module: base_location_geonames_import -#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:65 #, python-format -msgid "The country code inside the file (%s) doesn't correspond to the selected country (%s)." +msgid "The content of the file doesn't correspond to the selected country." msgstr "" diff --git a/base_location_geonames_import/i18n/fr.po b/base_location_geonames_import/i18n/fr.po index 699ad7519..bfd7eebf9 100644 --- a/base_location_geonames_import/i18n/fr.po +++ b/base_location_geonames_import/i18n/fr.po @@ -6,9 +6,9 @@ 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" +"POT-Creation-Date: 2014-04-07 15:01+0000\n" +"PO-Revision-Date: 2014-04-07 15:01+0000\n" +"Last-Translator: Alexis de Lattre \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -26,19 +26,19 @@ 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 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:64 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:87 #, 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." +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 entrées 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 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:88 #, 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." @@ -51,7 +51,7 @@ 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" +msgstr "Import Better Zip depuis Geonames" #. module: base_location_geonames_import #: view:better.zip.geonames.import:0 @@ -61,8 +61,8 @@ msgid "Import Geonames" msgstr "Importer Geonames" #. module: base_location_geonames_import -#: code:addons/base_location_geonames_import/wizard/geonames_import.py:67 +#: code:addons/base_location_geonames_import/wizard/geonames_import.py:65 #, 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)." +msgid "The content of the file doesn't correspond to the selected country." +msgstr "Le contenu du fichier ne correspond pas au pays sélectionné." diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index 79be0c2f7..d94a60e7c 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -42,25 +42,34 @@ class better_zip_geonames_import(orm.TransientModel): } def _prepare_better_zip( - self, cr, uid, row, country_id, context=None): + self, cr, uid, row, country_id, states, context=None): '''This function is designed to be inherited''' - return { + 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, context=None): + 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 content file doesn't correspond to the country")) + _("The content of the file doesn't correspond to the " + "selected country.")) logger.debug('ZIP = %s - City = %s' % (row[1], row[2])) - if row[1] and row[2] and 'CEDEX' not in row[1]: + if row[0] == 'FR' and 'CEDEX' in row[1]: + return False + if row[1] and row[2]: vals = self._prepare_better_zip( - cr, uid, row, country_id, context=context) + cr, uid, row, country_id, states, context=context) bzip_id = self.pool['res.better.zip'].create( cr, uid, vals, context=context) return bzip_id @@ -86,17 +95,29 @@ class better_zip_geonames_import(orm.TransientModel): 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') + 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, context=context) + cr, uid, row, country_id, country_code, states, + context=context) data_file.close() logger.info( 'The wizard to create better zip entries from geonames ' diff --git a/base_location_geonames_import/wizard/geonames_import_view.xml b/base_location_geonames_import/wizard/geonames_import_view.xml index 9608134b4..f86ea17da 100644 --- a/base_location_geonames_import/wizard/geonames_import_view.xml +++ b/base_location_geonames_import/wizard/geonames_import_view.xml @@ -14,9 +14,9 @@
-