~nbessi-c2c-deactivatedaccount/+junk/faulty_code_sample

« back to all changes in this revision

Viewing changes to base_location/company.py

  • Committer: Stefan Rijnhart
  • Author(s): nicolas.bessi at camptocamp
  • Date: 2013-07-09 10:52:49 UTC
  • mfrom: (19.2.16 city_into_better_zip)
  • Revision ID: stefan@therp.nl-20130709105249-g04fzp2cjlfqy4n9
[RFR] Porting city addons into better zip:
  -More complexe name get and name search.
  -Completion of country when changing state.
  -Zip object is added on company.
  -One2many from state to zip
  -Security is CSV
  -Spanish translation by Pedro M. Baeza

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Author: Nicolas Bessi. Copyright Camptocamp SA
 
5
#    Contributor: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>
 
6
#                 Ignacio Ibeas <ignacio@acysos.com>
 
7
#
 
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
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
from openerp.osv import orm, fields
 
23
 
 
24
 
 
25
class ResCompany(orm.Model):
 
26
 
 
27
    _inherit = 'res.company'
 
28
 
 
29
    def on_change_city(self, cr, uid, ids, zip_id, context=None):
 
30
        result = {}
 
31
        if context is None:
 
32
            context = {}
 
33
        if zip_id:
 
34
            bzip = self.pool['res.better.zip'].browse(cr, uid, zip_id, context=context)
 
35
            result = {'value': {'zip': bzip.name,
 
36
                                'country_id': bzip.country_id.id if bzip.country_id else False,
 
37
                                'city': bzip.city,
 
38
                                'state_id': bzip.state_id.id if bzip.state_id else False
 
39
                                }
 
40
                      }
 
41
        return result
 
42
 
 
43
    _columns = {
 
44
        'better_zip_id': fields.many2one('res.better.zip', 'Location', select=1,
 
45
                                         help=('Use the city name or the zip code'
 
46
                                         ' to search the location')),
 
47
    }