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
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5.Document.Coordinate import Coordinate
from Products.ERP5.Document.MetaNode import MetaNode
import string
class BankAccount(Folder, Coordinate):
class BankAccount(Folder, Coordinate, MetaNode):
"""
A bank account number holds a collection of numbers and codes
(ex. SWIFT, RIB, etc.) which may be used to identify a bank account.
......@@ -46,8 +47,8 @@ class BankAccount(Folder, Coordinate):
BankAccount inherits from Base and from the mix-in Coordinate.
"""
meta_type = 'ERP5 BankAccount'
portal_type = 'BankAccount'
meta_type = 'ERP5 Bank Account'
portal_type = 'Bank Account'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
......@@ -68,141 +69,148 @@ class BankAccount(Folder, 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')
def getIbanTextFormat(self):
"""
Returns the standard IBAN text format
"""
iban = self.getIban()
l = 4
s = "IBAN"
for i in range((len(iban) / l) + 1):
s += ' ' + iban[i*l : (i+1)*l]
return s.strip()
security.declareProtected(Permissions.View, 'getIbanTextFormat')
def getIban(self):
"""
The International Bank Account Number of this bank account.
IBAN is an international standard for identifying bank accounts worldwide.
"""
key = self.getIbanKey()
country_code = self.getBankCountryCode()
bban = self.getBban()
return (country_code + key + bban).upper().strip()
security.declareProtected(Permissions.View, 'getIbanKey')
def getIbanKey(self):
"""
The IBAN key ensure the integry of the IBAN code.
It's calculated with the ISO 7064 method (known as "97-10 modulo").
"""
# Construct the alpha to number translation table
table = {}
for i in range(26):
table[chr(65+i)] = str(10+i)
# Calcul the key
country_code = self.getBankCountryCode() + '00'
s = self.getBban() + country_code
n = ''
for c in s:
if c.isalpha():
n += table[c.upper()]
if c.isdigit():
n += c
key = str(98 - (int(n) % 97))
return key.zfill(2)
security.declareProtected(Permissions.View, 'getBban')
def getBban(self):
"""
The Basic Bank Account Number (BBAN) is the last part of the IBAN.
Usualy it correspond to the national bank account number.
"""
bank = self.getBankCode()
branch = self.getBranch()
ban = self.getBankAccountNumber()
key = self.getBbanKey()
return (bank + branch + ban + key).upper().strip()
security.declareProtected(Permissions.View, 'getBbanTextFormat')
def getBbanTextFormat(self, sep=' '):
"""
Returns a BBAN text format
"""
bank = self.getBankCode()
branch = self.getBranch()
ban = self.getBankAccountNumber()
key = self.getBbanKey()
return sep.join([bank, branch, ban, key]).upper().strip()
security.declareProtected(Permissions.View, 'getBbanKey')
def getBbanKey(self):
"""
The BBAN key ensure the integry of the BBAN code.
This is the french BBAN key algorithm.
"""
def transcode(string):
letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digit = '12345678912345678923456789'
for i in range(len(letter)):
string = string.replace(letter[i], digit[i])
return int(string)
bank = self.getBankCode()
branch = self.getBranch()
ban = self.getBankAccountNumber()
if len(bank + branch + ban) == 0:
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)
# XXX The following "helper methods" have been commented out, and kept in the
# code as an example.
# 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.
#
# 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')
# def getIbanTextFormat(self):
# """
# Returns the standard IBAN text format
# """
# iban = self.getIban()
# l = 4
# s = "IBAN"
# for i in range((len(iban) / l) + 1):
# s += ' ' + iban[i*l : (i+1)*l]
# return s.strip()
#
#
# security.declareProtected(Permissions.View, 'getIbanTextFormat')
# def getIban(self):
# """
# The International Bank Account Number of this bank account.
# IBAN is an international standard for identifying bank accounts worldwide.
# """
# key = self.getIbanKey()
# country_code = self.getBankCountryCode()
# bban = self.getBban()
# return (country_code + key + bban).upper().strip()
#
#
# security.declareProtected(Permissions.View, 'getIbanKey')
# def getIbanKey(self):
# """
# The IBAN key ensure the integry of the IBAN code.
# It's calculated with the ISO 7064 method (known as "97-10 modulo").
# """
# # Construct the alpha to number translation table
# table = {}
# for i in range(26):
# table[chr(65+i)] = str(10+i)
# # Calcul the key
# country_code = self.getBankCountryCode() + '00'
# s = self.getBban() + country_code
# n = ''
# for c in s:
# if c.isalpha():
# n += table[c.upper()]
# if c.isdigit():
# n += c
# key = str(98 - (int(n) % 97))
# return key.zfill(2)
#
#
# security.declareProtected(Permissions.View, 'getBban')
# def getBban(self):
# """
# The Basic Bank Account Number (BBAN) is the last part of the IBAN.
# Usualy it correspond to the national bank account number.
# """
# bank = self.getBankCode()
# branch = self.getBranch()
# ban = self.getBankAccountNumber()
# key = self.getBbanKey()
# return (bank + branch + ban + key).upper().strip()
#
#
# security.declareProtected(Permissions.View, 'getBbanTextFormat')
# def getBbanTextFormat(self, sep=' '):
# """
# Returns a BBAN text format
# """
# bank = self.getBankCode()
# branch = self.getBranch()
# ban = self.getBankAccountNumber()
# key = self.getBbanKey()
# return sep.join([bank, branch, ban, key]).upper().strip()
#
#
# security.declareProtected(Permissions.View, 'getBbanKey')
# def getBbanKey(self):
# """
# The BBAN key ensure the integry of the BBAN code.
# This is the french BBAN key algorithm.
# """
# def transcode(string):
# letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# digit = '12345678912345678923456789'
# for i in range(len(letter)):
# string = string.replace(letter[i], digit[i])
# return int(string)
#
# bank = self.getBankCode()
# branch = self.getBranch()
# ban = self.getBankAccountNumber()
# if len(bank + branch + ban) == 0:
# 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:
'type' : 'string',
'mode' : 'w'
},
{'id' : 'bank_account_holder_name',
'description' : 'The bank account holder\'s name',
'type' : 'string',
'mode' : 'w'
},
)
_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