Commit 43979ad5 authored by Alexandre Boeglin's avatar Alexandre Boeglin

- CreditCard is a form of BankAccount (a payment method). It must then use the

  same PropertySheet.
- Renammed the meta_type & portal_type according to the naming convention.
  (Added a whitespace. Is it a good idea ? It might have some side effects)
- There wa too many helper methods in BankAccount :
  It might be a potential hazard to have the system automatically fill in the
  security keys. It is far more secure to have the user enter them manually,
  and then have the system doucle-check them.
  This can be accomplished in ERP5 through the use of Constraint.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5266 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f66bce6f
...@@ -32,9 +32,10 @@ from AccessControl import ClassSecurityInfo ...@@ -32,9 +32,10 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Document.Folder import Folder from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5.Document.Coordinate import Coordinate from Products.ERP5.Document.Coordinate import Coordinate
from Products.ERP5.Document.MetaNode import MetaNode
import string import string
class BankAccount(Folder, Coordinate): class BankAccount(Folder, Coordinate, MetaNode):
""" """
A bank account number holds a collection of numbers and codes A bank account number holds a collection of numbers and codes
(ex. SWIFT, RIB, etc.) which may be used to identify a bank account. (ex. SWIFT, RIB, etc.) which may be used to identify a bank account.
...@@ -46,8 +47,8 @@ class BankAccount(Folder, Coordinate): ...@@ -46,8 +47,8 @@ class BankAccount(Folder, Coordinate):
BankAccount inherits from Base and from the mix-in Coordinate. BankAccount inherits from Base and from the mix-in Coordinate.
""" """
meta_type = 'ERP5 BankAccount' meta_type = 'ERP5 Bank Account'
portal_type = 'BankAccount' portal_type = 'Bank Account'
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
...@@ -68,141 +69,148 @@ class BankAccount(Folder, Coordinate): ...@@ -68,141 +69,148 @@ class BankAccount(Folder, Coordinate):
__implements__ = ( Interface.Coordinate ) __implements__ = ( Interface.Coordinate )
security.declareProtected(Permissions.View, 'getBankCode') # XXX The following "helper methods" have been commented out, and kept in the
def getBankCode(self, **kw): # code as an example.
""" # It might be a potential hazard to have the system automatically fill in the
Never return None. # security keys. It is far more secure to have the user enter them manually,
""" # and then have the system doucle-check them.
if self.bank_code == None: # This can be accomplished in ERP5 through the use of Constraint.
return '' #
return self.bank_code # security.declareProtected(Permissions.View, 'getBankCode')
# def getBankCode(self, **kw):
# """
security.declareProtected(Permissions.View, 'getBranch') # Never return None.
def getBranch(self, **kw): # """
""" # if self.bank_code == None:
Never return None. # return ''
""" # return self.bank_code
if self.branch == None: #
return '' #
return self.branch # security.declareProtected(Permissions.View, 'getBranch')
# def getBranch(self, **kw):
# """
security.declareProtected(Permissions.View, 'getBankAccountNumber') # Never return None.
def getBankAccountNumber(self, **kw): # """
""" # if self.branch == None:
Never return None. # return ''
""" # return self.branch
if self.bank_account_number == None: #
return '' #
return self.bank_account_number # security.declareProtected(Permissions.View, 'getBankAccountNumber')
# def getBankAccountNumber(self, **kw):
# """
security.declareProtected(Permissions.View, 'getBankCountryCode') # Never return None.
def getBankCountryCode(self, **kw): # """
""" # if self.bank_account_number == None:
Never return None. # return ''
""" # return self.bank_account_number
if self.bank_country_code == None: #
return '' #
return self.bank_country_code # security.declareProtected(Permissions.View, 'getBankCountryCode')
# def getBankCountryCode(self, **kw):
# """
security.declareProtected(Permissions.View, 'getIbanTextFormat') # Never return None.
def getIbanTextFormat(self): # """
""" # if self.bank_country_code == None:
Returns the standard IBAN text format # return ''
""" # return self.bank_country_code
iban = self.getIban() #
l = 4 #
s = "IBAN" # security.declareProtected(Permissions.View, 'getIbanTextFormat')
for i in range((len(iban) / l) + 1): # def getIbanTextFormat(self):
s += ' ' + iban[i*l : (i+1)*l] # """
return s.strip() # Returns the standard IBAN text format
# """
# iban = self.getIban()
security.declareProtected(Permissions.View, 'getIbanTextFormat') # l = 4
def getIban(self): # s = "IBAN"
""" # for i in range((len(iban) / l) + 1):
The International Bank Account Number of this bank account. # s += ' ' + iban[i*l : (i+1)*l]
IBAN is an international standard for identifying bank accounts worldwide. # return s.strip()
""" #
key = self.getIbanKey() #
country_code = self.getBankCountryCode() # security.declareProtected(Permissions.View, 'getIbanTextFormat')
bban = self.getBban() # def getIban(self):
return (country_code + key + bban).upper().strip() # """
# The International Bank Account Number of this bank account.
# IBAN is an international standard for identifying bank accounts worldwide.
security.declareProtected(Permissions.View, 'getIbanKey') # """
def getIbanKey(self): # key = self.getIbanKey()
""" # country_code = self.getBankCountryCode()
The IBAN key ensure the integry of the IBAN code. # bban = self.getBban()
It's calculated with the ISO 7064 method (known as "97-10 modulo"). # return (country_code + key + bban).upper().strip()
""" #
# Construct the alpha to number translation table #
table = {} # security.declareProtected(Permissions.View, 'getIbanKey')
for i in range(26): # def getIbanKey(self):
table[chr(65+i)] = str(10+i) # """
# Calcul the key # The IBAN key ensure the integry of the IBAN code.
country_code = self.getBankCountryCode() + '00' # It's calculated with the ISO 7064 method (known as "97-10 modulo").
s = self.getBban() + country_code # """
n = '' # # Construct the alpha to number translation table
for c in s: # table = {}
if c.isalpha(): # for i in range(26):
n += table[c.upper()] # table[chr(65+i)] = str(10+i)
if c.isdigit(): # # Calcul the key
n += c # country_code = self.getBankCountryCode() + '00'
key = str(98 - (int(n) % 97)) # s = self.getBban() + country_code
return key.zfill(2) # n = ''
# for c in s:
# if c.isalpha():
security.declareProtected(Permissions.View, 'getBban') # n += table[c.upper()]
def getBban(self): # if c.isdigit():
""" # n += c
The Basic Bank Account Number (BBAN) is the last part of the IBAN. # key = str(98 - (int(n) % 97))
Usualy it correspond to the national bank account number. # return key.zfill(2)
""" #
bank = self.getBankCode() #
branch = self.getBranch() # security.declareProtected(Permissions.View, 'getBban')
ban = self.getBankAccountNumber() # def getBban(self):
key = self.getBbanKey() # """
return (bank + branch + ban + key).upper().strip() # The Basic Bank Account Number (BBAN) is the last part of the IBAN.
# Usualy it correspond to the national bank account number.
# """
security.declareProtected(Permissions.View, 'getBbanTextFormat') # bank = self.getBankCode()
def getBbanTextFormat(self, sep=' '): # branch = self.getBranch()
""" # ban = self.getBankAccountNumber()
Returns a BBAN text format # key = self.getBbanKey()
""" # return (bank + branch + ban + key).upper().strip()
bank = self.getBankCode() #
branch = self.getBranch() #
ban = self.getBankAccountNumber() # security.declareProtected(Permissions.View, 'getBbanTextFormat')
key = self.getBbanKey() # def getBbanTextFormat(self, sep=' '):
return sep.join([bank, branch, ban, key]).upper().strip() # """
# Returns a BBAN text format
# """
security.declareProtected(Permissions.View, 'getBbanKey') # bank = self.getBankCode()
def getBbanKey(self): # branch = self.getBranch()
""" # ban = self.getBankAccountNumber()
The BBAN key ensure the integry of the BBAN code. # key = self.getBbanKey()
This is the french BBAN key algorithm. # return sep.join([bank, branch, ban, key]).upper().strip()
""" #
def transcode(string): #
letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # security.declareProtected(Permissions.View, 'getBbanKey')
digit = '12345678912345678923456789' # def getBbanKey(self):
for i in range(len(letter)): # """
string = string.replace(letter[i], digit[i]) # The BBAN key ensure the integry of the BBAN code.
return int(string) # This is the french BBAN key algorithm.
# """
bank = self.getBankCode() # def transcode(string):
branch = self.getBranch() # letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ban = self.getBankAccountNumber() # digit = '12345678912345678923456789'
if len(bank + branch + ban) == 0: # for i in range(len(letter)):
return '' # string = string.replace(letter[i], digit[i])
# return int(string)
bank += ('0' * (5 - len(bank))) #
branch += ('0' * (5 - len(branch))) # bank = self.getBankCode()
# branch = self.getBranch()
s = (bank + branch + ban).upper() # ban = self.getBankAccountNumber()
key = str(97 - ((transcode(s) * 100) % 97)) # if len(bank + branch + ban) == 0:
return key.zfill(2) # return ''
#
# bank += ('0' * (5 - len(bank)))
# branch += ('0' * (5 - len(branch)))
#
# s = (bank + branch + ban).upper()
# key = str(97 - ((transcode(s) * 100) % 97))
# return key.zfill(2)
...@@ -58,6 +58,11 @@ class BankAccount: ...@@ -58,6 +58,11 @@ class BankAccount:
'type' : 'string', 'type' : 'string',
'mode' : 'w' 'mode' : 'w'
}, },
{'id' : 'bank_account_holder_name',
'description' : 'The bank account holder\'s name',
'type' : 'string',
'mode' : 'w'
},
) )
_categories = ( 'source', ) _categories = ( 'source', )
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Alexandre Boeglin <alex@boeglin.org>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
class CreditCard:
"""
Properties for CreditCard Objects
"""
_properties = (
{'id' : 'card_number',
'description' : 'The 16 digits card number',
'type' : 'string',
'mode' : 'w'
},
{'id' : 'stop_date',
'description' : 'The expiry date of the card',
'type' : 'date',
'mode' : 'w'
},
{'id' : 'cardholder_name',
'description' : "The cardholder's name as it appears on the card",
'type' : 'string',
'mode' : 'w'
},
{'id' : 'security_key',
'description' : 'The 3 digits code at the back of the card (CVV2'\
' or CVC)',
'type' : 'string',
'mode' : 'w'
},
)
_categories = ( 'creditcard_type', )
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