Commit 65fe1bb1 authored by Kevin Deldycke's avatar Kevin Deldycke

Some properties must never return None.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4185 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 925ecf52
...@@ -70,115 +70,141 @@ class BankAccount(Folder, Coordinate): ...@@ -70,115 +70,141 @@ class BankAccount(Folder, Coordinate):
__implements__ = ( Interface.Coordinate ) __implements__ = ( Interface.Coordinate )
security.declareProtected(Permissions.View, 'getBankCode')
def getBankCode(self, **kw):
"""
Never return None.
"""
if self.bank_code == None:
return ''
return self.bank_code
security.declareProtected(Permissions.View, 'getBranch')
def getBranch(self, **kw):
"""
Never return None.
"""
if self.branch == None:
return ''
return self.branch
security.declareProtected(Permissions.View, 'getBankAccountNumber')
def getBankAccountNumber(self, **kw):
"""
Never return None.
"""
if self.bank_account_number == None:
return ''
return self.bank_account_number
security.declareProtected(Permissions.View, 'getBankCountryCode')
def getBankCountryCode(self, **kw):
"""
Never return None.
"""
if self.bank_country_code == None:
return ''
return self.bank_country_code
security.declareProtected(Permissions.View, 'getIbanTextFormat') security.declareProtected(Permissions.View, 'getIbanTextFormat')
def getIbanTextFormat(self): def getIbanTextFormat(self):
""" """
Returns the standard IBAN text format Returns the standard IBAN text format
""" """
iban = self.getIban() iban = self.getIban()
l = 4 l = 4
s = "IBAN" s = "IBAN"
for i in range((len(iban) / l) + 1): for i in range((len(iban) / l) + 1):
s += ' ' + iban[i*l : (i+1)*l] s += ' ' + iban[i*l : (i+1)*l]
return s.strip() return s.strip()
security.declareProtected(Permissions.View, 'getIbanTextFormat') security.declareProtected(Permissions.View, 'getIbanTextFormat')
def getIban(self): def getIban(self):
""" """
The International Bank Account Number of this bank account. The International Bank Account Number of this bank account.
IBAN is an international standard for identifying bank accounts worldwide. IBAN is an international standard for identifying bank accounts worldwide.
""" """
key = self.getIbanKey() key = self.getIbanKey()
country_code = self.getBankCountryCode() country_code = self.getBankCountryCode()
bban = self.getBban() bban = self.getBban()
if key == None: key = '' return (country_code + key + bban).upper().strip()
if country_code == None: country_code = ''
if bban == None: bban = ''
return (country_code + key + bban).upper().strip()
security.declareProtected(Permissions.View, 'getIbanKey') security.declareProtected(Permissions.View, 'getIbanKey')
def getIbanKey(self): def getIbanKey(self):
""" """
The IBAN key ensure the integry of the IBAN code. The IBAN key ensure the integry of the IBAN code.
It's calculated with the ISO 7064 method (known as "97-10 modulo"). It's calculated with the ISO 7064 method (known as "97-10 modulo").
""" """
# Construct the alpha to number translation table # Construct the alpha to number translation table
table = {} table = {}
for i in range(26): for i in range(26):
table[chr(65+i)] = str(10+i) table[chr(65+i)] = str(10+i)
# Calcul the key # Calcul the key
country_code = self.getBankCountryCode() + '00' country_code = self.getBankCountryCode() + '00'
s = self.getBban() + country_code s = self.getBban() + country_code
n = '' n = ''
for c in s: for c in s:
if c.isalpha(): if c.isalpha():
n += table[c.upper()] n += table[c.upper()]
if c.isdigit(): if c.isdigit():
n += c n += c
key = str(98 - (int(n) % 97)) key = str(98 - (int(n) % 97))
return key.zfill(2) return key.zfill(2)
security.declareProtected(Permissions.View, 'getBban') security.declareProtected(Permissions.View, 'getBban')
def getBban(self): def getBban(self):
""" """
The Basic Bank Account Number (BBAN) is the last part of the IBAN. The Basic Bank Account Number (BBAN) is the last part of the IBAN.
Usualy it correspond to the national bank account number. Usualy it correspond to the national bank account number.
""" """
bank = self.getBankCode() bank = self.getBankCode()
branch = self.getBranch() branch = self.getBranch()
ban = self.getBankAccountNumber() ban = self.getBankAccountNumber()
key = self.getBbanKey() key = self.getBbanKey()
if bank == None: bank = '' return (bank + branch + ban + key).upper().strip()
if branch == None: branch = ''
if ban == None: ban = ''
if key == None: key = ''
return (bank + branch + ban + key).upper().strip()
security.declareProtected(Permissions.View, 'getBbanTextFormat') security.declareProtected(Permissions.View, 'getBbanTextFormat')
def getBbanTextFormat(self, sep=' '): def getBbanTextFormat(self, sep=' '):
""" """
Returns a BBAN text format Returns a BBAN text format
""" """
bank = self.getBankCode() bank = self.getBankCode()
branch = self.getBranch() branch = self.getBranch()
ban = self.getBankAccountNumber() ban = self.getBankAccountNumber()
key = self.getBbanKey() key = self.getBbanKey()
if bank == None: bank = '' return sep.join([bank, branch, ban, key]).upper().strip()
if branch == None: branch = ''
if ban == None: ban = ''
if key == None: key = ''
return sep.join([bank, branch, ban, key]).upper().strip()
security.declareProtected(Permissions.View, 'getBbanKey') security.declareProtected(Permissions.View, 'getBbanKey')
def getBbanKey(self): def getBbanKey(self):
""" """
The BBAN key ensure the integry of the BBAN code. The BBAN key ensure the integry of the BBAN code.
This is the french BBAN key algorithm. This is the french BBAN key algorithm.
""" """
def transcode(string): def transcode(string):
letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digit = '12345678912345678923456789' digit = '12345678912345678923456789'
for i in range(len(letter)): for i in range(len(letter)):
string = string.replace(letter[i], digit[i]) string = string.replace(letter[i], digit[i])
return int(string) return int(string)
bank = self.getBankCode() bank = self.getBankCode()
branch = self.getBranch() branch = self.getBranch()
ban = self.getBankAccountNumber() ban = self.getBankAccountNumber()
if bank == None: bank = '' if len(bank + branch + ban) == 0:
if branch == None: branch = '' return ''
if ban == None: ban = ''
if len(bank + branch + ban) == 0: bank += ('0' * (5 - len(bank)))
return '' branch += ('0' * (5 - len(branch)))
bank += ('0' * (5 - len(bank))) s = (bank + branch + ban).upper()
branch += ('0' * (5 - len(branch))) key = str(97 - ((transcode(s) * 100) % 97))
return key.zfill(2)
s = (bank + branch + ban).upper() \ No newline at end of file
key = str(97 - ((transcode(s) * 100) % 97))
return key.zfill(2)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment