[IMP] l10n_ch: Improve code
[odoo/odoo.git] / addons / l10n_ch / partner.py
1 # -*- coding: utf-8 -*-
2 #
3 #  bank.py
4 #  partner.py
5 #
6 #  Created by Nicolas Bessi based on Credric Krier contribution
7 #
8 #  Copyright (c) 2009 CamptoCamp. All rights reserved.
9 ##############################################################################
10 # WARNING: This program as such is intended to be used by professional
11 # programmers who take the whole responsability of assessing all potential
12 # consequences resulting from its eventual inadequacies and bugs
13 # End users who are looking for a ready-to-use solution with commercial
14 # garantees and support are strongly adviced to contract a Free Software
15 # Service Company
16 #
17 # This program is Free Software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License
19 # as published by the Free Software Foundation; either version 2
20 # of the License, or (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
30 #
31 ##############################################################################
32
33 from osv import fields, osv
34
35 class res_partner(osv.osv):
36     _inherit = 'res.partner'
37
38     _columns = {
39         'ref_companies': fields.one2many('res.company', 'partner_id',
40         'Companies that refers to partner'),
41     }
42
43 res_partner()
44
45 class res_partner_bank(osv.osv):
46     _inherit = "res.partner.bank"
47     _columns = {
48         'name': fields.char('Description', size=128, required=True),
49         'post_number': fields.char('Post number', size=64),
50         'bvr_number': fields.char('BVR account number', size=11),
51         'bvr_adherent_num': fields.char('BVR adherent number', size=11),
52         'dta_code': fields.char('DTA code', size=5),
53     }
54
55 #   def _default_value(self, cursor, user, field, context=None):
56 #       if field in ('country_id', 'state_id'):
57 #           value = False
58 #       else:
59 #           value = ''
60 #       if not context.get('address', False):
61 #           return value
62 #       for ham, spam, address in context['address']:
63 #           if 'type' in address.keys() :
64 #               if address['type'] == 'default':
65 #                   return address[field]
66 #               elif not address['type']:
67 #                   value = address[field]
68 #           else :
69 #               value = False
70 #       return value
71
72
73     def name_get(self, cr, uid, ids, context=None):
74         if not len(ids):
75             return []
76         bank_type_obj = self.pool.get('res.partner.bank.type')
77
78         type_ids = bank_type_obj.search(cr, uid, [])
79         bank_type_names = {}
80         for bank_type in bank_type_obj.browse(cr, uid, type_ids,
81                 context=context):
82             bank_type_names[bank_type.code] = bank_type.name
83         res = []
84         for r in self.read(cr, uid, ids, ['name','state'], context):
85             res.append((r['id'], r['name']+' : '+bank_type_names[r['state']]))
86         return res
87
88     _sql_constraints = [
89         ('bvr_adherent_uniq', 'unique (bvr_adherent_num)', 'The BVR adherent number must be unique !')
90     ]
91
92 res_partner_bank()
93
94 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: