1
# -*- encoding: utf-8 -*-
2
##############################################################################
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
##############################################################################
27
from osv import osv, fields
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'}
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"/>
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),
78
class res_partner_address(osv.osv):
79
_name = 'res.partner.address'
80
_inherit = 'res.partner.address'
82
'region': fields.many2one('res.country.region', 'Region', domain="[('country_id', '=', country_id)]"),