[FIX] l10n_ch : default_value() of res.partner.bank corrected
[odoo/odoo.git] / addons / l10n_ch / partner.py
1 # -*- encoding: 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 import netsvc
34 from osv import fields, osv
35
36 class res_partner(osv.osv):
37         _inherit = 'res.partner'
38
39         _columns = {
40                 'ref_companies': fields.one2many('res.company', 'partner_id',
41                 'Companies that refers to partner'),
42         }
43         
44
45
46 res_partner()
47
48
49
50 class res_partner_bank(osv.osv):
51         _inherit = "res.partner.bank"
52         _columns = {
53                 'name': fields.char('Description', size=128, required=True),
54                 'post_number': fields.char('Post number', size=64),
55                 'bvr_number': fields.char('BVR account number', size=11),
56                 'bvr_adherent_num': fields.char('BVR adherent number', size=11),
57                 'dta_code': fields.char('DTA code', size=5),
58         }
59         
60         def _default_value(self, cursor, user, field, context=None):
61                 if field in ('country_id', 'state_id'):
62                         value = False
63                 else:
64                         value = ''
65                 if not context.get('address', False):
66                         return value
67                 for ham, spam, address in context['address']:
68                         if 'type' in address.keys() :
69                                 if address['type'] == 'default':
70                                         return address.get(field,False)
71                                 elif not address['type']:
72                                         value = address.get(field,False)
73                         else :
74                                 value = False
75                 return value
76                 
77                 
78         def name_get(self, cr, uid, ids, context=None):
79                 if not len(ids):
80                         return []
81                 bank_type_obj = self.pool.get('res.partner.bank.type')
82
83                 type_ids = bank_type_obj.search(cr, uid, [])
84                 bank_type_names = {}
85                 for bank_type in bank_type_obj.browse(cr, uid, type_ids,
86                                 context=context):
87                         bank_type_names[bank_type.code] = bank_type.name
88                 res = []
89                 for r in self.read(cr, uid, ids, ['name','state'], context):
90                         res.append((r['id'], r['name']+' : '+bank_type_names[r['state']]))
91                 return res
92         
93         _sql_constraints = [
94                 ('bvr_adherent_uniq', 'unique (bvr_adherent_num)', 'The BVR adherent number must be unique !')
95         ]
96
97         
98 res_partner_bank()
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: