~openerp-spain-team/openerp-spain/6.0-git

« back to all changes in this revision

Viewing changes to l10n_es_extras/l10n_ES_toponyms_region/l10n_ES_cpostal_region.py

  • Committer: Borja L.S.
  • Date: 2010-10-18 10:04:25 UTC
  • Revision ID: git-v1:271c47a993616dbba60585d48b8b98d603199d93
[REF] *: Refactorización para portar a 6.0 - Paso 1.

- Se han renombrado los módulos para usar la nomenclatura propuesta
  por OpenERP: l10n_es para el módulo base de localización (plan de 
  cuentas), l10n_es_* para el resto de módulos.

- Se eliminan los módulos extra_addons/* que deberían moverse a 
  los extra-addons genéricos (no son específicos de España).

- Se renombran los __terp__.py por __openerp__.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#
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
 
##############################################################################
23
 
 
24
 
import ir
25
 
import wizard
26
 
import pooler
27
 
from osv import osv, fields
28
 
import codecs
29
 
import tools
30
 
 
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'}
32
 
 
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"/>
38
 
</form>'''
39
 
 
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()
76
 
 
77
 
 
78
 
class res_partner_address(osv.osv):
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
 
    }
84
 
res_partner_address()