Note
license: GNU Lesser General Public License v3.0 (see LICENSE)
Parsing and validation utilites for the Spanish standard norm 43 by the “Consejo Superior Bancario” (CSB) / “Asociación Española de Banca” (AEB) for storing bank account transactions.
(es) Herramientas para leer y validar datos almacenados siguiendo la norma 43 del Consejo Superior Bancario (CSB) / Asociación Española de Banca (CSB).
See also
References:
A CSB43 file
Create a File object from a file descriptor:
>>> from csb43.csb43 import File
>>> with open("csb_file.csb") as fd:
... f = File(fd)
... # do something with f
...
Create an empty File object:
>>> f = File()
Parameters: |
|
---|---|
Raises: |
Return type: | iterator of all the CSB43 records that this object represents |
---|
>>> import csb43.csb43 as csb
>>> f = csb.File()
>>> f.add_account(csb.Account())
>>> f.add_transaction(csb.Transaction())
>>> for x in f:
... print x
...
11 000000000000000000000000000000
22 0000000000000000000001000000000000000000000000000000000000
88999999999999999999000002
>>>
Return type: | representation of this object as CSB43 records (using \n as separator) |
---|
>>> import csb43.csb43 as csb
>>> f = csb.File()
>>> f.add_account(csb.Account())
>>> f.add_transaction(csb.Transaction())
>>> print f
11 000000000000000000000000000000
22 0000000000000000000001000000000000000000000000000000000000
88999999999999999999000002
list of weak references to the object (if defined)
Return type: | ClosingFile file abstract |
---|
Return type: | list of accounts |
---|
Add a new account
Parameters: | record (Account or basestring) – account record |
---|---|
Raises: | csb43.utils.Csb43Exception if record is not valid |
Add a new additional exchange record to the last added transaction
Parameters: |
|
---|---|
Raises: |
See also
Add a new additional item record to the last added transaction
Parameters: | record (Item or basestring) – item record |
---|---|
Raises: | csb43.utils.Csb43Exception when the record is impossible to parse, or if the maximum number of complementary items has been reached |
See also
Add a new transaction to the last added account
Parameters: | record (Transaction or basestring) – transaction record |
---|---|
Raises: | csb43.utils.Csb43Exception |
See also
Return type: | a representation of this object as a dict. The keys will be localised |
---|
>>> import csb43.csb43 as csb
>>> f = csb.File()
>>> f.add_account(csb.Account())
>>> f.add_transaction(csb.Transaction())
>>> import pprint
>>> pprint.pprint(f.as_dict())
{u'cuentas': [{u'balance_inicial': None,
u'codigo_de_entidad': None,
u'codigo_de_sucursal': None,
u'divisa': None,
u'fecha_de_comienzo': None,
u'fecha_de_fin': None,
u'modalidad_de_informacion': None,
u'movimientos': [{u'cantidad': None,
u'codigo_de_sucursal': None,
u'concepto_comun': None,
u'concepto_propio': None,
u'fecha_de_operacion': None,
u'fecha_valor': None,
u'numero_del_documento': None,
u'primera_referencia': None,
u'segunda_referencia': None}],
u'nombre_abreviado': None,
u'numero_de_cuenta': None}]}
Close the current account
Parameters: | record (ClosingAccount or basestring) – csb record |
---|---|
Raises: | csb43.utils.Csb43Exception if record is not valid |
See also
Close the file with a termination record
Parameters: | record (ClosingFile or basestring) – csb record |
---|---|
Raises: | csb43.utils.Csb43Exception if record is not valid |
If record is None, a new abstract is generated:
>>> c = csb.File()
>>> c.is_closed()
False
>>> c.close_file()
>>> c.is_closed()
True
>>> c.abstract.totalRecords
0
>>> c.add_account(csb.Account())
>>> c.abstract.totalRecords
0
>>> c.close_file()
>>> c.abstract.totalRecords
1
>>> c.is_closed()
True
If record is not empty, the number of records of File must be coincident with the quantity given in record:
>>> cf = csb.ClosingFile()
>>> cf.totalRecords = 5
>>> c.close_file(cf)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "csb43/csb43/csb_file.py", line 200, in close_file
File "csb43/utils/utils.py", line 25, in raiseCsb43Exception
raise exc
csb43.utils.utils.Csb43Exception: registro de cierre de fichero incongruente: total de registros 5 != 1
>>>
Return type: | True if this File has been properly closed |
---|
A File abstract, given by a termination record
Create a ClosingFile object from a CSB43 string record:
>>> from csb43.csb43 import ClosingFile
>>> c = ClosingFile(record)
From an empty object to a CSB43 string record:
>>> c = ClosingFile()
>>> c.totalRecords = 123
>>> str(c)
'88999999999999999999000123 '
Parameters: |
|
---|---|
Raises: |
Return type: | representation of this object as CSB43 records (using \n as separator) |
---|
list of weak references to the object (if defined)
padding
total number of entries
>>> c.totalRecords = 34
>>> c.totalRecords
34
>>> c.totalRecords = '115'
>>> c.totalRecords
115
A Csb43 account / (es) Cuenta
Create an Account object from a CSB43 string record:
>>> from csb43.csb43 import Account
>>> a = Account(record)
From an empty object to a CSB43 string record:
>>> a = Account()
>>> str(a)
'11 000000000000000000000000000000 '
Parameters: |
|
---|---|
Raises: |
Return type: | iterator of all the CSB43 records that this object represents |
---|
Return type: | representation of this object as CSB43 records (using \n as separator) |
---|
Return type: | ClosingAccount account abstract |
---|
account number / (es) numero de cuenta
Return type: | str |
---|
>>> a.accountNumber = '0000000000'
>>> a.accountNumber
'0000000000'
Add a new additional exchange record to the last added transaction
Parameters: |
|
---|---|
Raises: |
See also
Add a new additional item record to the transaction
Parameters: | record (Item or basestring) – item record |
---|---|
Raises: | csb43.utils.Csb43Exception when the record is impossible to parse, or if the maximum number of complementary items has been reached |
See also
Add a new transaction to the account
Parameters: | record (Transaction or basestring) – transaction record |
---|---|
Raises: | csb43.utils.Csb43Exception |
bank code / (es) codigo de banco
Return type: | str |
---|
>>> a.bankCode = '0000'
>>> a.bankCode
'0000'
branch code / (es) codigo de sucursal u oficina
Return type: | str |
---|
>>> a.branchCode = '0000'
>>> a.branchCode
'0000'
Close the current account and generate an abstract object
Parameters: |
|
---|---|
Raises: | csb43.utils.Csb43Exception if invalid record or incongruent abstract |
currency object / (es) objecto de divisa
Return type: | pycountry.db.Currency |
---|
ISO 4217 codes can be assigned:
>>> a.currency = 'USD'
>>> a.currency.letter
u'USD'
>>> a.currency.numeric
u'840'
>>> a.currency = '978'
>>> a.currency.letter
u'EUR'
End date of the period to which the information corresponds / (es) fecha de fin del periodo al que corresponde la informacion
Return type: | datetime.datetime |
---|
Setting a date:
>>> a.finalDate = datetime.datetime(year=2012,month=2,day=13).date()
>>> a.finalDate
datetime.datetime(2012, 2, 13, 0, 0)
Return type: | int two-digits checksum for the bank account / (es) digitos de control |
---|
Return type: | the last added Transaction |
---|
information mode / (es) modalidad de informacion
>>> a.informationMode = 1
>>> a.informationMode
1
>>> a.informationMode = '2'
>>> a.informationMode
2
initial balance amount / (es) montante del balance inicial
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> a.initialBalance = 123
>>> a.initialBalance
123.0
>>> a.initialBalance = 123.45
>>> a.initialBalance
123.45
>>> a.initialBalance = '1234.56'
>>> a.initialBalance
1234.56
>>> a.initialBalance = 1.2345
>>> a.initialBalance
1.23
Start date of the period to which the information corresponds / (es) fecha de comienzo del periodo al que corresponde la informacion
Return type: | datetime.datetime |
---|
Setting a date:
>>> a.initialDate = datetime.datetime(year=2012,month=2,day=13).date()
>>> a.initialDate
datetime.datetime(2012, 2, 13, 0, 0)
padding
abbreviated name of the client / (es) nombre abreviado del cliente
Return type: | str |
---|
list of transactions / (es) lista de movimientos
An Account abstact, given by a termination record
Parameters: |
|
---|---|
Raises: |
account number / (es) numero de cuenta
final balance / (es) balance final
bank code / (es) codigo de banco
branch code / (es) codigo de sucursal u oficina
currency object (pycountry.db.Currency) /(es) objecto de divisa
total debit amounts / (es) montante total en el debe
number of debit entries / (es) numero de entradas en el debe
total credit amounts / (es) montante total en el haber
number of credit entries / (es) numero de entradas en el haber
padding
A Csb43 transaction / (es) Movimiento
Create a Transaction object from a CSB43 string record:
>>> from csb43.csb43 import Transaction
>>> t = Transaction(record)
From an empty object to a CSB43 string record:
>>> t = Transaction()
>>> t.amount = 123.45
>>> str(t)
'22 0000000000000000000002000000000123450000000000000000000000 '
Parameters: |
|
---|---|
Raises: |
Return type: | iterator of all the CSB43 records that this object represents |
---|
>>> [x for x in t]
['22 0000000000120213000002000000001234560000000000012345678900 something', '2301first item record ', '2302second item record ', '240184000000000012300 ']
Return type: | representation of this object as CSB43 records (using \n as separator) |
---|
>>> str(t)
'22 000000000012021300000200000000123456000000000001234567890\
0 something\n2301first item recor\
d \n2302\
second item recor\
d \n2401840000000\
00012300 '
Add a new additional exchange record to the transaction
Parameters: |
|
---|---|
Raises: |
Add an exchange object from a CSB43 string record:
>>> from csb43.csb43 import Exchange
>>> record = '{: <80}'.format('240197800000000012345')
>>> t.add_exchange(record)
>>> str(t.exchange)
'240197800000000012345 '
Add an exchange object from a Exchange:
>>> from csb43.csb43 import Exchange
>>> e = Exchange()
>>> e.amount = 123.45
>>> e.sourceCurrency = 'EUR'
>>> t.add_exchange(e)
>>> str(t.exchange)
'240197800000000012345 '
Add a new optional item to the transaction.
Parameters: | record (Item or basestring) – item record |
---|---|
Raises: | csb43.utils.Csb43Exception when the record is impossible to parse, or if the maximum number of complementary items has been reached |
amount of the transaction / (es) cantidad implicada en el movimiento
Return type: | float |
---|
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> t.amount = 123
>>> t.amount
123.0
>>> t.amount = 123.45
>>> t.amount
123.45
>>> t.amount = '1234.56'
>>> t.amount
1234.56
>>> t.amount = 1.2345
>>> t.amount
1.23
Return type: | a representation of this object as a dict. The keys will be localised |
---|
>>> t.as_dict()
{u'cantidad': 123.45, u'primera_referencia': None, u'segunda_referencia': None, u'concepto_propio': None, u'fecha_de_operacion': None, u'numero_del_documento': None, u'codigo_de_sucursal': None, u'concepto_comun': None, u'fecha_valor': None}
branch code / (es) código de sucursal u oficina
Return type: | str |
---|
>>> t.branchCode = '0000'
>>> t.branchCode
'0000'
document number / (es) número del documento
Return type: | int |
---|
>>> t.documentNumber = 1
>>> t.documentNumber
1
list of optional items / (es) lista de conceptos adicionales
Return type: | list of Item attached to this transaction |
---|
own item (given by each bank to its transactions) / (es) concepto propio del banco
Return type: | str |
---|
>>> t.ownItem = 123
>>> t.ownItem
'123'
>>> t.ownItem = '125'
>>> t.ownItem
'125'
padding
first reference (checksummed) / (es) primera referencia (verificada)
Return type: | str |
---|
>>> t.reference1 = '012345678900'
>>> t.reference1
'012345678900'
>>> try:
... t.reference1 = '012345678901'
... except Exception, e:
... print e
...
Validación fallida para el campo de referencia '012345678901'
second reference (not checksummed) / (es) segunda referencia (no verificada)
Return type: | str |
---|
>>> t.reference2 = '{: >16}'.format('something')
>>> t.reference2
' something'
inter-bank shared item / (es) concepto común
Return type: | str |
---|
>>> t.sharedItem = 12
>>> t.sharedItem
'12'
>>> t.sharedItem = '04'
>>> t.sharedItem
'04'
>>> from csb43.csb43 import utils
>>> utils.CONCEPTOS[t.sharedItem]
'GIROS - TRANSFERENCIAS - TRASPASOS - CHEQUES'
transaction date / (es) fecha de la operación
Return type: | datetime.datetime |
---|
Setting a date:
>>> t.transactionDate = datetime.datetime(year=2012,month=2,day=13).date()
>>> t.transactionDate
datetime.datetime(2012, 2, 13, 0, 0)
value date / (es) fecha valor
Return type: | datetime.datetime |
---|
Setting a date:
>>> t.valueDate = datetime.datetime(year=2012,month=2,day=13).date()
>>> t.valueDate
datetime.datetime(2012, 2, 13, 0, 0)
Complementary item / (es) Concepto adicional (registro 23)
Create an Item object from a CSB43 string record:
>>> from csb43.csb43 import Item
>>> record = '2301primer concepto adicional segundo concepto adicional '
>>> i = Item(record)
>>> i.item1
'primer concepto adicional'
>>> i.item2
'segundo concepto adicional'
>>> i.recordCode
1
From an empty object to a CSB43 string record:
>>> i = Item()
>>> i.item1 = 'primer concepto adicional'
>>> i.item2 = 'segundo concepto adicional'
>>> i.recordCode = 1
>>> str(i)
'2301primer concepto adicional segundo concepto adicional '
Parameters: |
|
---|---|
Raises: |
Return type: | representation of this object as a CSB43 record |
---|
list of weak references to the object (if defined)
Return type: | a representation of this object as a dict. The keys will be localised |
---|
>>> i.as_dict()
{u'concepto1': 'primer concepto adicional', u'concepto2': 'segundo concepto adicional', u'codigo_de_registro': 1}
first additional item / (es) primer concepto adicional
second additional item / (es) segundo concepto adicional
code of record / (es) codigo de registro
Code can be assigned as a number or as a string:
>>> i.recordCode = 1
>>> i.recordCode
1
>>> i.recordCode = '2'
>>> i.recordCode
2
>>> i.recordCode = '01'
>>> i.recordCode
1
>>> try:
... i.recordCode = 10
... except Exception, e:
... print e
...
mal formato: el contenido '10' no concuerda con el formato esperado r'^0[12345]$' para este campo
Exchange record / (es) registro de cambio de divisa (24)
Parameters: |
|
---|---|
Raises: |
Create an Exchange object from a CSB43 string record:
>>> from csb43.csb43 import Exchange
>>> record = '{: <80}'.format('240197800000000012345')
>>> e = Exchange(record)
>>> print e.amount
123.45
>>> print e.sourceCurrency.letter
EUR
>>> print e.sourceCurrency.numeric
978
From an empty object to a CSB43 string record:
>>> from csb43.csb43 import Exchange
>>> e = Exchange()
>>> e.amount = 123.45
>>> e.sourceCurrency = 'EUR'
>>> print e
240197800000000012345
Return type: | representation of this object as a CSB43 record |
---|
amount in the original currency / (es) cantidad en la divisa original
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> e.amount = 123
>>> e.amount
123.0
>>> e.amount = 123.45
>>> e.amount
123.45
>>> e.amount = '1234.56'
>>> e.amount
1234.56
>>> e.amount = 1.2345
>>> e.amount
1.23
Return type: | a representation of this object as a dict. The keys will be localised |
---|
>>> e.as_dict()
{u'divisa_original': 'EUR', u'cantidad': 1.23}
padding
original currency / (es) divisa original
ISO 4217 codes can be assigned:
>>> e.sourceCurrency = 'USD'
>>> e.sourceCurrency.letter
u'USD'
>>> e.sourceCurrency.numeric
u'840'
>>> e.sourceCurrency = '978'
>>> e.sourceCurrency.letter
u'EUR'
As well as a pycountry.db.Currency object:
>>> import pycountry
>>> e.sourceCurrency = pycountry.currencies.get(letter='EUR')
>>> e.sourceCurrency = pycountry.currencies.get(letter='USD')
>>> e.sourceCurrency.letter
u'USD'
>>> type(e.sourceCurrency)
<class 'pycountry.db.Currency'>