~camptocamp/c2c-rd-addons/8.0a

« back to all changes in this revision

Viewing changes to account_payment_edifact/res_partner_bank.py

  • Committer: ferdinand
  • Date: 2011-04-30 20:34:01 UTC
  • Revision ID: office@chricar.at-20110430203401-eqfv4au4tv3faj93
[ADD] initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################
 
3
#
 
4
# Swing Entwicklung betrieblicher Informationssysteme GmbH
 
5
# (<http://www.swing-system.com>)
 
6
# Copyright (C) ChriCar Beteiligungs- und Beratungs- GmbH
 
7
# all rights reserved
 
8
#    05-MAR-2011 (GK) created
 
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 3
 
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, 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.
 
31
#
 
32
###############################################
 
33
from osv import fields, osv
 
34
from tools.translate import _
 
35
 
 
36
class res_partner_bank(osv.osv) :
 
37
    _inherit = "res.partner.bank"
 
38
 
 
39
    def _construct_iban(self, p_bank):
 
40
        iban    = False
 
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
 
45
            if   country == "AT":
 
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)
 
50
            elif country == "DE":
 
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)
 
55
        return iban
 
56
    # end def _construct_iban
 
57
 
 
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
 
61
 
 
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)
 
66
            if iban :
 
67
                fban = self._format_iban(iban)
 
68
                self.write(cr, uid, [partner_bank.id], {'iban' : fban, 'state' : 'iban'})
 
69
# end class res_partner_bank
 
70
res_partner_bank()
 
71
 
 
72
class payment_line(osv.osv):
 
73
    _inherit = 'payment.line'
 
74
    
 
75
    _columns = \
 
76
        { 'bank_account_type': fields.related
 
77
            ( 'bank_id'
 
78
            , 'state'
 
79
            , type='char', size=16
 
80
            , store     = False
 
81
            , relation  = 'res.partner_bank'
 
82
            , string    = 'Bank Account Type'
 
83
            )
 
84
        }
 
85
 
 
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)
 
90
 
 
91
payment_line()
 
92
 
 
93
class payment_order(osv.osv):
 
94
    _inherit = 'payment.order'
 
95
 
 
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)
 
101
payment_order()