1
1
# -*- encoding: utf-8 -*-
2
2
##############################################################################
4
# Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
5
# Jordi Esteve <jesteve@zikzakmedia.com>
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
6
# Jordi Esteve <jesteve@zikzakmedia.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
36
31
com_auto={'00':'', '01':'EK', '02':'CM', '03':'PV', '04':'AN', '05':'CL', '06':'EX', '07':'IB', '08':'CA', '09':'CL', '10':'EX', '11':'AN', '12':'PV', '13':'CM', '14':'AN', '15':'GA', '16':'CM', '17':'CA', '18':'AN', '19':'CM', '20':'EK', '21':'AN', '22':'AR', '23':'AN', '24':'CL', '25':'CA', '26':'LR', '27':'GA', '28':'MA', '29':'AN', '30':'MU', '31':'NA', '32':'GA', '33':'AS', '34':'CL', '35':'IC', '36':'GA', '37':'CL', '38':'IC', '39':'CB', '40':'CL', '41':'AN', '42':'CL', '43':'CA', '44':'AR', '45':'CM', '46':'PV', '47':'CL', '48':'EK', '49':'CL', '50':'AR', '51':'CE', '52':'ME'}
38
cpostal_end_form = '''<?xml version="1.0"?>
39
<form string="Codis postals">
40
<separator string="Resultat:" colspan="4"/>
41
<label string="Se han asociado las Comunidades Autónomas a los códigos postales del Estado Español." colspan="4" align="0.0"/>
42
<label string="Permite rellenar automáticamente el campo de Comunidad Autónoma del formulario de empresa y contacto a partir del código postal" colspan="4" align="0.0"/>
33
zipcode_end_form = '''<?xml version="1.0" encoding="utf-8"?>
34
<form string="Zip codes">
35
<separator string="Result:" colspan="4"/>
36
<label string="The regions has been associated to the Spanish zip codes." colspan="4" align="0.0"/>
37
<label string="This allows to fill automatically the region field of partner and contact forms from the zip code." colspan="4" align="0.0"/>
45
class l10n_ES_crea_cpostal_CA(wizard.interface):
46
def _crea_cpostal(self, cr, uid, data, context):
47
pool = pooler.get_pool(cr.dbname)
49
con = codecs.open(tools.config['addons_path']+'/l10n_ES_toponyms_CA/cpostal.csv','r','utf-8')
51
codi = linea[:-5] #aqui tinc els 2 primers digits del cp
52
ids = pool.get('res.country.cautonoma').search(cr, uid, [('code', '=', com_auto[codi])])
54
ir.ir_set(cr, uid, 'default', 'zip='+linea[:-2], 'cautonoma', [('res.partner.address', False)], ids[0])
60
'actions': [_crea_cpostal],
63
'arch':cpostal_end_form,
65
'state':[('end', 'Accepta', 'gtk-ok'),]
70
l10n_ES_crea_cpostal_CA('l10n_ES_toponyms_CA.crea_cpostal')
73
class cautonoma(osv.osv):
74
_name = 'res.country.cautonoma'
75
_description = 'Comunidad Autónoma'
77
'country_id': fields.many2one('res.country', 'País', required=True),
78
'name': fields.char('Nombre', size=64, required=True),
79
'code': fields.char('Código', size=10),
40
class l10n_ES_create_zipcode_region(wizard.interface):
41
def _create_zipcode(self, cr, uid, data, context):
42
from cpostal import cod_postales
43
pool = pooler.get_pool(cr.dbname)
44
for m in cod_postales:
45
codi = m[0][:-3] #2 primeros dígitos del cp
46
ids = pool.get('res.country.region').search(cr, uid, [('code', '=', com_auto[codi])])
48
ir.ir_set(cr, uid, 'default', 'zip='+m[0], 'region', [('res.partner.address', False)], ids[0])
53
'actions': [_create_zipcode],
56
'arch':zipcode_end_form,
58
'state':[('end', 'Ok', 'gtk-ok'),]
63
l10n_ES_create_zipcode_region('l10n_ES_toponyms_region.create_zipcode')
66
class region(osv.osv):
67
_name = 'res.country.region'
68
_description = 'Region'
70
'country_id': fields.many2one('res.country', 'Country', required=True),
71
'name': fields.char('Name', size=64, required=True),
72
'code': fields.char('Code', size=10),
85
78
class res_partner_address(osv.osv):
86
_name = 'res.partner.address'
87
_inherit = 'res.partner.address'
89
'cautonoma': fields.many2one('res.country.cautonoma', 'C. Autónoma', domain="[('country_id', '=', country_id)]"),
79
_name = 'res.partner.address'
80
_inherit = 'res.partner.address'
82
'region': fields.many2one('res.country.region', 'Region', domain="[('country_id', '=', country_id)]"),
91
84
res_partner_address()