1
# -*- coding: utf-8 -*-
2
##############################################
4
# Swing Entwicklung betrieblicher Informationssysteme GmbH
5
# (<http://www.swing-system.com>)
6
# Copyright (C) ChriCar Beteiligungs- und Beratungs- GmbH
8
# 05-MAR-2011 (GK) created
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
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 3
20
# of the License, or (at your option) any later version.
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.
27
# You should have received a copy of the GNU General Public License
28
# along with this program; if not, see <http://www.gnu.org/licenses/> or
29
# write to the Free Software Foundation, Inc.,
30
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
###############################################
33
from osv import fields, osv
34
from tools.translate import _
36
class res_partner_bank(osv.osv) :
37
_inherit = "res.partner.bank"
39
def _construct_iban(self, p_bank):
41
account = p_bank.acc_number
42
blz = p_bank.bank.code
43
if p_bank.bank.country:
44
country = p_bank.bank.country.code
46
xblz = "%05i" % int(blz)
47
xaccount = "%011i" % int(account)
48
prz = "%02i" % (98 - int(xblz + xaccount + "102900") % 97)
49
iban = ("AT" + prz + xblz + xaccount)
51
xblz = "%08i" % int(blz)
52
xaccount = "%010i" % int(account)
53
prz = "%02i" % (98 - int(xblz + xaccount + "131400") % 97)
54
iban = ("DE" + prz + xblz + xaccount)
56
# end def _construct_iban
58
def _format_iban(self, iban):
59
return " ".join([iban[i:i+4] for i in range(0, len(iban), 4)])
60
# end def _format_iban
62
def convert2iban(self, cr, uid, ids, id):
63
for partner_bank in self.browse(cr, uid, ids):
64
if partner_bank.state == "iban" or partner_bank.iban: continue # already exists
65
iban = self._construct_iban(partner_bank)
67
fban = self._format_iban(iban)
68
self.write(cr, uid, [partner_bank.id], {'iban' : fban, 'state' : 'iban'})
69
# end class res_partner_bank
72
class payment_line(osv.osv):
73
_inherit = 'payment.line'
76
{ 'bank_account_type': fields.related
79
, type='char', size=16
81
, relation = 'res.partner_bank'
82
, string = 'Bank Account Type'
86
def convert2iban(self, cr, uid, ids, id):
87
partner_bank_obj = self.pool.get('res.partner.bank')
88
for payment_line in self.browse(cr, uid, ids):
89
partner_bank_obj.convert2iban(cr, uid, [payment_line.bank_id.id], id)
93
class payment_order(osv.osv):
94
_inherit = 'payment.order'
96
def convert2iban(self, cr, uid, ids, id):
97
payment_line_obj = self.pool.get('payment.line')
98
for payment_order in self.browse(cr, uid, ids):
99
for payment_line in payment_order.line_ids :
100
payment_line_obj.convert2iban(cr, uid, [payment_line.id], id)