From 2db30761917e998c78b3ec63c40f8df1ee64da9d Mon Sep 17 00:00:00 2001
From: "Pieter J. Kersten"
Date: Thu, 6 Jan 2011 21:05:36 +0100
Subject: [PATCH] [FIX] account_banking: fix unused typo in sepa code [IMP]
account_banking: do not consult online convertor for dutch 7 scheme
accounts, but calculate our own.
---
account_banking/sepa/iban.py | 4 ++--
account_banking/sepa/online.py | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/account_banking/sepa/iban.py b/account_banking/sepa/iban.py
index e4b0cef27..92b6ed120 100644
--- a/account_banking/sepa/iban.py
+++ b/account_banking/sepa/iban.py
@@ -42,7 +42,7 @@
# account owning banks. Don't use it, unless you are prepared to loose your
# money. It is for heuristic validation purposes only.
-__all__ = ['IBAN']
+__all__ = ['IBAN', 'BBAN']
def modulo_97_base10(abuffer):
'''
@@ -312,7 +312,7 @@ class IBAN(str):
format = cls.BBAN_formats[countrycode]
if BBAN:
- if len(BBAN) == len(formats._iban):
+ if len(BBAN) == len(format._iban):
ibanno = cls(countrycode + '00' + BBAN)
return cls(countrycode + ibanno.checksum + BBAN)
raise ValueError, \
diff --git a/account_banking/sepa/online.py b/account_banking/sepa/online.py
index fe50bd717..65003b3bc 100644
--- a/account_banking/sepa/online.py
+++ b/account_banking/sepa/online.py
@@ -45,7 +45,22 @@ def get_iban_bic_NL(bank_acc):
banks operating in the Netherlands and will only convert Dutch local
account numbers.
'''
- data = urllib.urlencode(dict(number=bank_acc.lstrip('0'), method='POST'))
+ # sanity check: Dutch 7 scheme uses ING as sink and online convertor
+ # calculates accounts, so no need to consult it - calculate our own
+ number = bank_acc.lstrip('0')
+ if len(number) <= 7:
+ return struct(
+ iban = IBAN(BBAN='INGB' + number.rjust(10, '0'),
+ countrycode='NL'
+ ).replace(' ',''),
+ account = iban,
+ bic = 'INGBNL2A',
+ code = 'INGBNL',
+ bank = 'ING Bank N.V.'
+ country_id = 'NL',
+ )
+
+ data = urllib.urlencode(dict(number=number, method='POST'))
request = urllib2.Request(IBANlink_NL, data)
response = urllib2.urlopen(request)
soup = BeautifulSoup(response)