~sergio-incaser/openerp-spain/openerp-spain

« back to all changes in this revision

Viewing changes to l10n_es_extras/l10n_ES_toponyms_region/l10n_ES_cpostal_region.py

  • Committer: Jordi Esteve
  • Date: 2009-12-14 17:53:50 UTC
  • mfrom: (81.1.90 lp-openerp-spain-5.0)
  • Revision ID: jesteve@zikzakmedia.com-20091214175350-6vzzt3avtsof25a2
Recuperación del estado actual del repositorio de localización española de OpenERP: Aplicación de todos los merges pendientes desde la versión 81 (15-11-2008) hasta la actual (02-12-2009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
2
##############################################################################
3
3
#
4
 
# Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
5
 
#                                       Jordi Esteve <jesteve@zikzakmedia.com>
6
 
#
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
12
 
# Service Company
13
 
#
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.
18
 
#
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.
23
 
#
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.
27
 
#
 
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>
 
7
#    $Id$
 
8
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
#
 
22
##############################################################################
28
23
 
29
24
import ir
30
25
import wizard
35
30
 
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'}
37
32
 
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"/>
43
38
</form>'''
44
39
 
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)
48
 
                
49
 
                con = codecs.open(tools.config['addons_path']+'/l10n_ES_toponyms_CA/cpostal.csv','r','utf-8')
50
 
                for linea in con:
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])])
53
 
                        if ids:
54
 
                                ir.ir_set(cr, uid, 'default', 'zip='+linea[:-2], 'cautonoma', [('res.partner.address', False)], ids[0])
55
 
                con.close()
56
 
                return {}
57
 
 
58
 
        states = {
59
 
                'init': {
60
 
                        'actions': [_crea_cpostal],
61
 
                        'result': {
62
 
                                'type':'form',
63
 
                                'arch':cpostal_end_form,
64
 
                                'fields': {},
65
 
                                'state':[('end', 'Accepta', 'gtk-ok'),]
66
 
                        }
67
 
                }
68
 
                
69
 
        }
70
 
l10n_ES_crea_cpostal_CA('l10n_ES_toponyms_CA.crea_cpostal')
71
 
 
72
 
 
73
 
class cautonoma(osv.osv):
74
 
        _name = 'res.country.cautonoma'
75
 
        _description = 'Comunidad Autónoma'
76
 
        _columns = {
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),
80
 
                        }
81
 
        _order = 'name'
82
 
cautonoma()
 
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])])
 
47
            if ids:
 
48
                ir.ir_set(cr, uid, 'default', 'zip='+m[0], 'region', [('res.partner.address', False)], ids[0])
 
49
        return {}
 
50
 
 
51
    states = {
 
52
        'init': {
 
53
            'actions': [_create_zipcode],
 
54
            'result': {
 
55
                'type':'form',
 
56
                'arch':zipcode_end_form,
 
57
                'fields': {},
 
58
                'state':[('end', 'Ok', 'gtk-ok'),]
 
59
            }
 
60
        }
 
61
 
 
62
    }
 
63
l10n_ES_create_zipcode_region('l10n_ES_toponyms_region.create_zipcode')
 
64
 
 
65
 
 
66
class region(osv.osv):
 
67
    _name = 'res.country.region'
 
68
    _description = 'Region'
 
69
    _columns = {
 
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),
 
73
            }
 
74
    _order = 'name'
 
75
region()
83
76
 
84
77
 
85
78
class res_partner_address(osv.osv):
86
 
        _name = 'res.partner.address'
87
 
        _inherit = 'res.partner.address'
88
 
        _columns = {
89
 
                'cautonoma': fields.many2one('res.country.cautonoma', 'C. Autónoma', domain="[('country_id', '=', country_id)]"),
90
 
        }
 
79
    _name = 'res.partner.address'
 
80
    _inherit = 'res.partner.address'
 
81
    _columns = {
 
82
        'region': fields.many2one('res.country.region', 'Region', domain="[('country_id', '=', country_id)]"),
 
83
    }
91
84
res_partner_address()