Browse Source

Add support for states (if states are already present in res.country.state).

Add POT file and FR translation.
pull/22/head
Alexis de Lattre 11 years ago
committed by Lorenzo Battistini
parent
commit
9f942f9b73
  1. 68
      base_location_geonames_import/i18n/base_location_geonames_import.pot
  2. 68
      base_location_geonames_import/i18n/fr.po
  3. 37
      base_location_geonames_import/wizard/geonames_import.py
  4. 4
      base_location_geonames_import/wizard/geonames_import_view.xml

68
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-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"
"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: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."
msgstr ""
#. module: base_location_geonames_import
#: 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 ""
#. 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:65
#, python-format
msgid "The content of the file doesn't correspond to the selected country."
msgstr ""

68
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-07 15:01+0000\n"
"PO-Revision-Date: 2014-04-07 15:01+0000\n"
"Last-Translator: Alexis de Lattre <alexis.delattre@akretion.com>\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: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 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: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."
#. 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 depuis 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:65
#, python-format
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é."

37
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 '

4
base_location_geonames_import/wizard/geonames_import_view.xml

@ -14,9 +14,9 @@
<field name="arch" type="xml">
<form string="Import Geonames" version="7.0">
<group name="main">
<label string="This wizard will delete all the better zip entries for the selected country, download the latest version from geonames.org for that country and create new better zip entries."
colspan="2" name="import-help"/>
<field name="country_id"/>
<label string="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."
colspan="2" name="import-help"/>
</group>
<footer>
<button name="run_import" type="object"

Loading…
Cancel
Save