1
# -*- encoding: utf-8 -*-
2
########################################################################
4
# @authors: Ignacio Ibeas <ignacio@acysos.com>
5
# Copyright (C) 2013 Acysos S.L.
7
#This program is free software: you can redistribute it and/or modify
8
#it under the terms of the GNU General Public License as published by
9
#the Free Software Foundation, either version 3 of the License, or
10
#(at your option) any later version.
12
# This module is GPLv3 or newer and incompatible
13
# with OpenERP SA "AGPL + Private Use License"!
15
#This program is distributed in the hope that it will be useful,
16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
#GNU General Public License for more details.
20
#You should have received a copy of the GNU General Public License
21
#along with this program. If not, see http://www.gnu.org/licenses.
22
########################################################################
24
from osv import fields, osv
25
from tools.translate import _
28
_mapping = {'A': '10', 'B': '11', 'C': '12', 'D': '13', 'E': '14', 'F': '15',
29
'G': '16', 'H': '17', 'I': '18', 'J': '19', 'K': '20', 'L': '21',
30
'M': '22', 'N': '23', 'O': '24', 'P': '25', 'Q': '26', 'R': '27',
31
'S': '28', 'T': '29', 'U': '30', 'V': '31', 'W': '32', 'X': '33',
35
class wizard_partner_cc_iban(osv.osv_memory):
36
_name = "wizard.partner.cc.iban"
37
_description = "Wizard Partner CC IBAN"
39
def _bank_type_get(self, cr, uid, context=None):
40
partner_bank_obj = self.pool.get('res.partner.bank')
41
return partner_bank_obj._bank_type_get(cr, uid, context=context)
44
'bank_state': fields.selection(_bank_type_get, 'Bank Account Type',
48
def update_cc_iban(self, cr, uid, ids, context=None):
51
data = self.read(cr, uid, ids, context=context)[0]
52
bank_obj = self.pool.get('res.partner.bank')
53
partner_obj = self.pool.get('res.partner')
54
partner_ids = context.get('active_ids')
56
for partner in partner_obj.browse(cr, uid, partner_ids,
59
for bank in partner.bank_ids:
61
country = bank.acc_country_id
63
country = bank.bank.country
64
new_data['acc_country_id'] = country.id
65
if bank.state == data['bank_state']:
67
if bank.state == 'bank':
68
iban = self.convert_to_iban(cr, uid,
75
elif bank.state == 'iban':
76
ccc = self.convert_to_ccc(cr, uid, bank.iban,
81
bank_obj.write(cr, uid, [bank.id], new_data,
83
return {'type': 'ir.actions.act_window_close'}
85
def convert_to_iban(self, cr, uid, acc_number, country_code, context=None):
86
code_char = _mapping[country_code[:1]] + _mapping[country_code[1:]]
87
ccc = acc_number.replace(" ", "")
88
for key, replacement in _mapping.items():
89
ccc_number = ccc.replace(key, replacement)
90
ccc_convert = int(ccc_number + code_char + '00')
91
remainder = ccc_convert % 97
92
control_digit = 98 - remainder
93
if control_digit < 10:
94
control_digit = '0' + str(control_digit)
96
control_digit = str(control_digit)
97
iban = country_code + control_digit + str(ccc)
100
def convert_to_ccc(self, cr, uid, iban, context=None):
101
ccc = iban.replace(" ", "")
104
wizard_partner_cc_iban()