~agilebg/openobject-italia/7.0-bug-1284569-hurrinico

« back to all changes in this revision

Viewing changes to l10n_it_base/partner/partner.py

  • Committer: Lorenzo Battistini
  • Date: 2013-10-17 15:33:07 UTC
  • mfrom: (223.1.2 italia-addons-7.0)
  • Revision ID: lorenzo.battistini@agilebg.com-20131017153307-uagzlkr7rtu5247z
[FIX] bug 1239610

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
2
##############################################################################
3
 
#    
4
 
#    Copyright (C) 2010 OpenERP Italian Community (<http://www.openerp-italia.org>). 
5
 
#    All Rights Reserved
6
 
#    $Id$
 
3
#
 
4
#    Copyright (C) 2010 OpenERP Italian Community
 
5
#    (<http://www.openerp-italia.org>).
 
6
#    Copyright (C) 2010 Associazione OpenERP Italia.
7
7
#
8
8
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU Affero General Public License as published by
10
 
#    the Free Software Foundation, either version 3 of the License, or
 
9
#    it under the terms of the GNU Affero General Public License as published
 
10
#    by the Free Software Foundation, either version 3 of the License, or
11
11
#    (at your option) any later version.
12
12
#
13
13
#    This program is distributed in the hope that it will be useful,
14
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
 
16
#    GNU Affero General Public License for more details.
17
17
#
18
18
#    You should have received a copy of the GNU General Public License
19
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
24
from osv import fields
25
25
from tools.translate import _
26
26
 
 
27
 
27
28
class res_region(osv.osv):
28
29
    _name = 'res.region'
29
30
    _description = 'Region'
30
31
    _columns = {
31
 
        'name': fields.char('Region Name', size=64, help='The full name of the region.', required=True),
 
32
        'name': fields.char(
 
33
            'Region Name', size=64, help='The full name of the region.',
 
34
            required=True),
32
35
        'country_id': fields.many2one('res.country', 'Country'),
33
36
    }
34
37
res_region()
35
38
 
 
39
 
36
40
class res_province(osv.osv):
37
41
    _name = 'res.province'
38
42
    _description = 'Province'
39
43
    _columns = {
40
 
        'name': fields.char('Province Name', size=64, help='The full name of the province.', required=True),
41
 
        'code': fields.char('Province Code', size=2, help='The province code in two chars.',required=True),
42
 
        'region': fields.many2one('res.region','Region'),
 
44
        'name': fields.char(
 
45
            'Province Name', size=64, help='The full name of the province.',
 
46
            required=True),
 
47
        'code': fields.char(
 
48
            'Province Code', size=2, help='The province code in two chars.',
 
49
            required=True),
 
50
        'region': fields.many2one('res.region', 'Region'),
43
51
    }
44
52
 
45
53
res_province()
46
54
 
 
55
 
47
56
class res_city(osv.osv):
48
57
    _name = 'res.city'
49
58
    _description = 'City'
50
59
    _columns = {
51
60
        'name': fields.char('City', size=64, required=True),
52
 
        'province_id': fields.many2one('res.province','Province'),
 
61
        'province_id': fields.many2one('res.province', 'Province'),
53
62
        'zip': fields.char('ZIP', size=5),
54
 
        'phone_prefix': fields.char('Telephone Prefix' , size=16),
 
63
        'phone_prefix': fields.char('Telephone Prefix', size=16),
55
64
        'istat_code': fields.char('ISTAT code', size=16),
56
65
        'cadaster_code': fields.char('Cadaster Code', size=16),
57
66
        'web_site': fields.char('Web Site', size=64),
58
 
        'region': fields.related('province_id','region',type='many2one', relation='res.region', string='Region', readonly=True),
 
67
        'region': fields.related(
 
68
            'province_id', 'region', type='many2one', relation='res.region',
 
69
            string='Region', readonly=True),
59
70
    }
60
71
 
 
72
 
61
73
class res_partner(osv.osv):
62
74
    _inherit = 'res.partner'
63
75
 
67
79
    }
68
80
 
69
81
    def on_change_city(self, cr, uid, ids, city):
70
 
        res = {'value':{}}
 
82
        res = {'value': {}}
71
83
        if(city):
72
 
            city_id = self.pool.get('res.city').search(cr, uid, [('name', '=', city.title())])
 
84
            city_id = self.pool.get('res.city').search(
 
85
                cr, uid, [('name', '=ilike', city)])
73
86
            if city_id:
74
 
                city_obj = self.pool.get('res.city').browse(cr, uid, city_id[0])
 
87
                city_obj = self.pool.get('res.city').browse(
 
88
                    cr, uid, city_id[0])
75
89
                res = {'value': {
76
 
                    'province': city_obj.province_id and city_obj.province_id.id or False,
 
90
                    'province': (
 
91
                        city_obj.province_id and city_obj.province_id.id
 
92
                        or False
 
93
                    ),
77
94
                    'region': city_obj.region and city_obj.region.id or False,
78
95
                    'zip': city_obj.zip,
79
 
                    'country_id': city_obj.region and city_obj.region.country_id and city_obj.region.country_id.id or False,
 
96
                    'country_id': (
 
97
                        city_obj.region and
 
98
                        city_obj.region.country_id and
 
99
                        city_obj.region.country_id.id or False
 
100
                    ),
80
101
                    'city': city.title(),
81
 
                    }}
 
102
                }
 
103
                }
82
104
        return res
83
105
 
84
106
    def _set_vals_city_data(self, cr, uid, vals):
85
 
        if vals.has_key('city') and not vals.has_key('province') and not vals.has_key('region'):
 
107
        if 'city' in vals and 'province' not in vals and 'region' not in vals:
86
108
            if vals['city']:
87
 
                city_obj= self.pool.get('res.city')
88
 
                city_ids = city_obj.search(cr, uid, [('name', '=', vals['city'].title())])
 
109
                city_obj = self.pool.get('res.city')
 
110
                city_ids = city_obj.search(
 
111
                    cr, uid, [('name', '=ilike', vals['city'])])
89
112
                if city_ids:
90
113
                    city = city_obj.browse(cr, uid, city_ids[0])
91
 
                    if not vals.has_key('zip'):
 
114
                    if 'zip' not in vals:
92
115
                        vals['zip'] = city.zip
93
116
                    if city.province_id:
94
117
                        vals['province'] = city.province_id.id
105
128
    def write(self, cr, uid, ids, vals, context=None):
106
129
        vals = self._set_vals_city_data(cr, uid, vals)
107
130
        return super(res_partner, self).write(cr, uid, ids, vals, context)
108
 
    
 
131
 
109
132
res_partner()