-
Notifications
You must be signed in to change notification settings - Fork 1
/
formato iban.py
78 lines (72 loc) · 2.46 KB
/
formato iban.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import oerplib
import os
import time
host= 'localhost'
protocol= 'xmlrpc'
port=8069
dbname = 'prevencontrol'
username = 'XXXXX'
pwd = 'XXXXX'
oerp = oerplib.OERP(host, dbname, protocol, port)
user = oerp.login(username, pwd)
import unicodedata
def elimina_tildes(s):
s=unicode(s)
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
###### quitar espacios en ccc de la cuentas de prevencontrol ##################
def mod97(digit_string):
"""Modulo 97 for huge numbers given as digit strings.
This function is a prototype for a JavaScript implementation.
In Python this can be done much easier: long(digit_string) % 97.
"""
m = 0
for d in digit_string:
m = (m * 10 + int(d)) % 97
return m
#cálculo del formato iban de una cuenta bancaria
def calc_iban(acc_number):
iban = "ES" + "00" + acc_number
code = iban[:2]
checksum = iban[2:4]
bban = iban[4:]
digits = ""
for ch in bban.upper():
if ch.isdigit():
digits += ch
else:
digits += str(ord(ch) - ord("A") + 10)
for ch in code:
digits += str(ord(ch) - ord("A") + 10)
digits += checksum
checksum = 98 - mod97(digits)
checksum = (str(checksum)).zfill(2)
return "ES" + checksum + acc_number
#recorrer todas las cuentas bancarias calculando el iban
bank_ids = oerp.execute('res.partner.bank', 'search', [])
# bank_ids=[4]
l=len(bank_ids)
c=0
for bank_id in bank_ids:
c+=1
print (c,l)
bank = oerp.browse('res.partner.bank', bank_id)
print bank.id
bank_owner_name=bank.owner_name
bank_city=bank.city
bank_zip=bank.zip
country_id = 67
acc_country_id = 67
if bank.acc_number:
acc_number = (bank.acc_number).replace(" ","")
acc_number = acc_number.replace("-","")
iban = calc_iban(acc_number)
print acc_number
print iban
oerp.write('res.partner.bank', [bank_id], {'city':bank_city, 'owner_name':bank_owner_name, 'zip':bank_zip, 'country_id':country_id, 'acc_country_id':acc_country_id, 'acc_number': acc_number, 'iban':iban})
elif bank.iban:
acc_number = (bank.iban)[2:]
print acc_number
print iban
oerp.write('res.partner.bank', [bank_id], {'city':bank_city, 'owner_name':bank_owner_name, 'zip':bank_zip, 'country_id':country_id, 'acc_country_id':acc_country_id, 'acc_number': acc_number, 'iban':iban})