66
66
return 'invalid-dc'
67
67
return '%s %s %s %s' % (bank, office, dc, account)
69
def _pretty_iban(iban_str):
70
"return iban_str in groups of four characters separated by a single space"
73
res.append(iban_str[:4])
74
iban_str = iban_str[4:]
69
77
class res_partner_bank(osv.osv):
70
78
_inherit = 'res.partner.bank'
72
80
'acc_country_id': fields.many2one("res.country", 'Bank country', help="If the country of the bank is Spain, it validates the bank code. It only reads the digit characters of the bank code:\n- If the number of digits is 18, computes the two digits of control.\n- If the number of digits is 20, computes the two digits of control and ignores the current ones.\n- If the number of digits is different from 18 or 20, it leaves the bank code unaltered.\nThe result is shown in the '1234 5678 06 1234567890' format."),
75
def onchange_banco(self, cr, uid, ids, account, country_id, context=None):
83
def onchange_banco(self, cr, uid, ids, account, country_id, state, context=None):
76
84
if account and country_id:
77
85
country = self.pool.get('res.country').browse(cr, uid, country_id, context)
78
if country.code.upper() in ('ES', 'CT'):
79
number = checkBankAccount(account)
80
if number == 'invalid-size':
81
return { 'warning': { 'title': _('Warning'), 'message': _('Bank account should have 20 digits.') } }
82
if number == 'invalid-dc':
83
return { 'warning': { 'title': _('Warning'), 'message': _('Invalid bank account.') } }
84
bank_ids = self.pool.get('res.bank').search(cr, uid, [('code','=',number[:4])], context=context)
86
return {'value':{'acc_number': number, 'bank': bank_ids[0]}}
88
return {'value':{'acc_number': number}}
86
if country.code.upper() in ('ES'):
87
bank_obj = self.pool.get('res.bank')
89
number = checkBankAccount( account )
90
if number == 'invalid-size':
91
return { 'warning': { 'title': _('Warning'),
92
'message': _('Bank account should have 20 digits.') } }
93
if number == 'invalid-dc':
94
return { 'warning': { 'title': _('Warning'),
95
'message': _('Invalid bank account.') } }
97
bank_ids = bank_obj.search(cr, uid,
98
[('code','=',number[:4])],
101
return {'value':{'acc_number': number,
102
'bank': bank_ids[0]}}
104
return {'value':{'acc_number': number}}
106
partner_bank_obj = self.pool.get('res.partner.bank')
107
if partner_bank_obj.is_iban_valid(cr,uid,account,context):
108
number = _pretty_iban(account.replace(" ", ""))
110
bank_ids = bank_obj.search(cr, uid,
111
[('code','=',number[5:9])],
114
return {'value':{'acc_number': number,
115
'bank': bank_ids[0]}}
117
return {'value':{'acc_number': number}}
119
return { 'warning': { 'title': _('Warning'),
120
'message': _('IBAN account is not valid') } }
89
121
return {'value':{}}
91
123
res_partner_bank()