Load default zip data from csv file throw a wizard
This commit is contained in:
parent
3003071284
commit
37f94e0639
13
__init__.py
13
__init__.py
|
@ -1,7 +1,16 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
#This file is part country_zip_es module for Tryton.
|
#This file is part country_zip_es module for Tryton.
|
||||||
#The COPYRIGHT file at the top level of this repository contains
|
#The COPYRIGHT file at the top level of this repository contains
|
||||||
#the full copyright notices and license terms.
|
#the full copyright notices and license terms.
|
||||||
|
|
||||||
|
from trytond.pool import Pool
|
||||||
|
from .country_zip import *
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
pass
|
Pool.register(
|
||||||
|
LoadCountryZipsStart,
|
||||||
|
module='country_zip_es', type_='model')
|
||||||
|
Pool.register(
|
||||||
|
LoadCountryZips,
|
||||||
|
module='country_zip_es', type_='wizard')
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
#This file is part of country_zip_es module for Tryton.
|
||||||
|
#The COPYRIGHT file at the top level of this repository contains
|
||||||
|
#the full copyright notices and license terms.
|
||||||
|
from csv import reader
|
||||||
|
from trytond.model import ModelView
|
||||||
|
from trytond.pool import Pool, PoolMeta
|
||||||
|
from trytond.wizard import Button, StateView, Wizard, StateTransition
|
||||||
|
import os
|
||||||
|
|
||||||
|
__all__ = ['LoadCountryZipsStart', 'LoadCountryZips']
|
||||||
|
__metaclass__ = PoolMeta
|
||||||
|
|
||||||
|
|
||||||
|
class LoadCountryZipsStart(ModelView):
|
||||||
|
'''Load Country Zips Start'''
|
||||||
|
__name__ = 'load.country.zips.start'
|
||||||
|
|
||||||
|
|
||||||
|
class LoadCountryZips(Wizard):
|
||||||
|
'''Load Country Zips'''
|
||||||
|
__name__ = "load.country.zips"
|
||||||
|
|
||||||
|
start = StateView('load.country.zips.start',
|
||||||
|
'country_zip_es.load_country_zips_start_view_form', [
|
||||||
|
Button('Cancel', 'end', 'tryton-cancel'),
|
||||||
|
Button('Accept', 'accept', 'tryton-ok', default=True),
|
||||||
|
])
|
||||||
|
accept = StateTransition()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(LoadCountryZips, cls).__setup__()
|
||||||
|
cls._error_messages.update({
|
||||||
|
'error': 'CSV Import Error!',
|
||||||
|
'read_error': 'Error reading file: %s.\nError raised: %s.',
|
||||||
|
})
|
||||||
|
|
||||||
|
def transition_accept(self):
|
||||||
|
pool = Pool()
|
||||||
|
Subdivision = pool.get('country.subdivision')
|
||||||
|
CountryZip = pool.get('country.zip')
|
||||||
|
|
||||||
|
delimiter = ','
|
||||||
|
quotechar = '"'
|
||||||
|
data = open(os.path.join(
|
||||||
|
os.path.dirname(__file__), 'country_zip_es.csv'))
|
||||||
|
try:
|
||||||
|
rows = reader(data, delimiter=delimiter, quotechar=quotechar)
|
||||||
|
except TypeError, e:
|
||||||
|
self.raise_user_error('error',
|
||||||
|
error_description='read_error',
|
||||||
|
error_description_args=('bank.csv', e))
|
||||||
|
rows.next()
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
if not row:
|
||||||
|
continue
|
||||||
|
|
||||||
|
countryzips = CountryZip.search([
|
||||||
|
('zip', '=', row[0]),
|
||||||
|
('subdivision', '=', row[2])
|
||||||
|
])
|
||||||
|
if countryzips:
|
||||||
|
countryzip = countryzips[0]
|
||||||
|
else:
|
||||||
|
countryzip = CountryZip()
|
||||||
|
countryzip.zip = row[0]
|
||||||
|
countryzip.subdivision = Subdivision.search([
|
||||||
|
('code', '=', row[2]),
|
||||||
|
], limit=1)[0]
|
||||||
|
countryzip.city = row[1]
|
||||||
|
countryzip.save()
|
||||||
|
|
||||||
|
return 'end'
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- This file is part of country_zip_es module for Tryton.
|
||||||
|
The COPYRIGHT file at the top level of this repository contains the full
|
||||||
|
copyright notices and license terms. -->
|
||||||
|
<tryton>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- load.country.zips wizard -->
|
||||||
|
<record model="ir.ui.view" id="load_country_zips_start_view_form">
|
||||||
|
<field name="model">load.country.zips.start</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">load_country_zips_start_form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.action.wizard" id="load_country_zips_action_wizard">
|
||||||
|
<field name="name">Load country zips of Spain</field>
|
||||||
|
<field name="wiz_name">load.country.zips</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.module.module.config_wizard.item"
|
||||||
|
id="config_wizard_load_country_zips">
|
||||||
|
<field name="action" ref="load_country_zips_action_wizard"/>
|
||||||
|
<field name="sequence" eval="40"/>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</tryton>
|
File diff suppressed because it is too large
Load Diff
57912
country_zip_es.xml
57912
country_zip_es.xml
File diff suppressed because it is too large
Load Diff
|
@ -2,4 +2,4 @@
|
||||||
Códigos postales de España
|
Códigos postales de España
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
Añade los datos maestros de ciudades y códigos postales de España.
|
Añade los datos por defecto (ciudad y subdivisión) relacionados con los códigos postales de España.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Country Zip Module Spanish l10n
|
Country Zip Module Spanish l10n
|
||||||
###############################
|
###############################
|
||||||
|
|
||||||
The country zip spanish l10n module add data source country zip (zip, city, subdivision)
|
The country zip Spanish l10n module adds default data (city and subdivision) related to Spanish zips.
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||||
|
|
||||||
|
msgctxt "error:load.country.zips:"
|
||||||
|
msgid "CSV Import Error!"
|
||||||
|
msgstr "Error importació CSV"
|
||||||
|
|
||||||
|
msgctxt "error:load.country.zips:"
|
||||||
|
msgid ""
|
||||||
|
"Error reading file: %s.\n"
|
||||||
|
"Error raised: %s."
|
||||||
|
msgstr ""
|
||||||
|
"Error llegint fitxer: %s.\n"
|
||||||
|
"Error obtingut: %s."
|
||||||
|
|
||||||
|
msgctxt "field:load.country.zips.start,id:"
|
||||||
|
msgid "ID"
|
||||||
|
msgstr "ID"
|
||||||
|
|
||||||
|
msgctxt "model:ir.action,name:load_country_zips_action_wizard"
|
||||||
|
msgid "Load country zips of Spain"
|
||||||
|
msgstr "Afegeix els codis postals d'Espanya"
|
||||||
|
|
||||||
|
msgctxt "model:load.country.zips.start,name:"
|
||||||
|
msgid "Load Country Zips Start"
|
||||||
|
msgstr "Inici afegir codis postals"
|
||||||
|
|
||||||
|
msgctxt "view:load.country.zips.start:"
|
||||||
|
msgid "Load country zips for Spain"
|
||||||
|
msgstr "Afegeix els codis postals d'Espanya"
|
||||||
|
|
||||||
|
msgctxt "view:load.country.zips.start:"
|
||||||
|
msgid ""
|
||||||
|
"This process will load all Spanish default data (city and subdivision) "
|
||||||
|
"related to zips in the database."
|
||||||
|
msgstr ""
|
||||||
|
"Aquest procés afegirà totes les dades per defecte (ciutat i subdivisió) "
|
||||||
|
"relacionades amb els codis postals d'Espanya."
|
||||||
|
|
||||||
|
msgctxt "wizard_button:load.country.zips,start,accept:"
|
||||||
|
msgid "Accept"
|
||||||
|
msgstr "Accepta"
|
||||||
|
|
||||||
|
msgctxt "wizard_button:load.country.zips,start,end:"
|
||||||
|
msgid "Cancel"
|
||||||
|
msgstr "Cancel·la"
|
|
@ -0,0 +1,47 @@
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||||
|
|
||||||
|
msgctxt "error:load.country.zips:"
|
||||||
|
msgid "CSV Import Error!"
|
||||||
|
msgstr "Error de importación CSV"
|
||||||
|
|
||||||
|
msgctxt "error:load.country.zips:"
|
||||||
|
msgid ""
|
||||||
|
"Error reading file: %s.\n"
|
||||||
|
"Error raised: %s."
|
||||||
|
msgstr ""
|
||||||
|
"Error leyendo fichero: %s.\n"
|
||||||
|
"Error obtenido: %s."
|
||||||
|
|
||||||
|
msgctxt "field:load.country.zips.start,id:"
|
||||||
|
msgid "ID"
|
||||||
|
msgstr "ID"
|
||||||
|
|
||||||
|
msgctxt "model:ir.action,name:load_country_zips_action_wizard"
|
||||||
|
msgid "Load country zips of Spain"
|
||||||
|
msgstr "Añadir los códigos postales de España"
|
||||||
|
|
||||||
|
msgctxt "model:load.country.zips.start,name:"
|
||||||
|
msgid "Load Country Zips Start"
|
||||||
|
msgstr "Inicio añadir códigos postales"
|
||||||
|
|
||||||
|
msgctxt "view:load.country.zips.start:"
|
||||||
|
msgid "Load country zips for Spain"
|
||||||
|
msgstr "Añadir los códigos postales de España"
|
||||||
|
|
||||||
|
msgctxt "view:load.country.zips.start:"
|
||||||
|
msgid ""
|
||||||
|
"This process will load all Spanish default data (city and subdivision) "
|
||||||
|
"related to zips in the database."
|
||||||
|
msgstr ""
|
||||||
|
"Este proceso añadirá todos los datos por defecto (ciudad y subdivisión) "
|
||||||
|
"relacionados con los códigos postales de España."
|
||||||
|
|
||||||
|
msgctxt "wizard_button:load.country.zips,start,accept:"
|
||||||
|
msgid "Accept"
|
||||||
|
msgstr "Aceptar"
|
||||||
|
|
||||||
|
msgctxt "wizard_button:load.country.zips,start,end:"
|
||||||
|
msgid "Cancel"
|
||||||
|
msgstr "Cancelar"
|
|
@ -3,4 +3,4 @@ version=3.0.0
|
||||||
depends:
|
depends:
|
||||||
country_zip
|
country_zip
|
||||||
xml:
|
xml:
|
||||||
country_zip_es.xml
|
country_zip.xml
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- This file is part of country_zip_es module for Tryton.
|
||||||
|
The COPYRIGHT file at the top level of this repository contains the full
|
||||||
|
copyright notices and license terms. -->
|
||||||
|
<form string="Load country zips for Spain">
|
||||||
|
<image name="tryton-dialog-information" xexpand="0" xfill="0"/>
|
||||||
|
<label string="This process will load all Spanish default data (city and subdivision) related to zips in the database."
|
||||||
|
id="load_country_zips"
|
||||||
|
yalign="0.0" xalign="0.0" xexpand="1"/>
|
||||||
|
<newline/>
|
||||||
|
</form>
|
Loading…
Reference in New Issue