CFONB 120 support¶
What the loader reads from a CFONB 120 statement, where each field sits on each record, and how amounts are signed. This page is the README's Features section, included verbatim so the two cannot drift.
Public API¶
from bankstatementparser_loader_cfonb import (
CfonbStatementParser,
CfonbSummary,
load_cfonb,
load_cfonb_file,
summarize_cfonb,
)
| Class / Function | Signature | Returns |
|---|---|---|
load_cfonb |
load_cfonb(text_or_lines): a str or an iterable of lines |
list[Transaction] |
load_cfonb_file |
load_cfonb_file(path): a str or os.PathLike |
list[Transaction] |
summarize_cfonb |
summarize_cfonb(text_or_lines): a str or an iterable of lines |
CfonbSummary |
CfonbStatementParser |
CfonbStatementParser(file_name) |
BankStatementParser with parse() (DataFrame), to_transactions() and get_summary() (dict) |
CfonbSummary is a frozen dataclass with the fields account_id, bank_code, branch_code, currency, opening_balance, closing_balance (Decimal or None), opening_date, closing_date, transaction_count, total_credit and total_debit (both positive Decimals).
Record layout¶
Every record is 120 characters and starts with its code: 01 (ancien solde, the opening balance), 04 (an operation), 05 (complementary detail of the preceding operation) or 07 (nouveau solde, the closing balance). The loader reads these columns (1-based, inclusive); tests/test_docs_accuracy.py checks every row of this table against the parser:
| Columns | Field Name | Records | Description |
|---|---|---|---|
3-7 |
Bank Code | 01, 04 | Code banque |
8-11 |
Internal Operation Code | 04 | Not read |
12-16 |
Branch Code | 01, 04 | Code guichet |
17-19 |
Currency | 01, 04 | ISO 4217 code; EUR when blank |
20 |
Number Of Decimals | 01 | Scale of every amount; 2 when blank |
22-32 |
Account Number | 01, 04 | The transaction's account_id |
33-34 |
Interbank Operation Code | 04 | Kept as category cfonb:<code> |
35-40 |
Date | 01, 04, 07 | JJMMAA: the balance date, or the operation (booking) date |
43-48 |
Value Date | 04 | JJMMAA; the operation date when blank |
49-79 |
Label | 04 | Libellé, the start of the description |
82-88 |
Entry Number | 04 | Numéro d'écriture, kept as reference |
91-104 |
Amount | 01, 04, 07 | 13 digits and a signed units character, see below |
49-118 |
Complementary Information | 05 | Appended to the operation's description |
On 04 records a blank bank, branch, currency or account takes the 01 header's value.
Mapping to Transaction¶
Transaction field |
Source |
|---|---|
account_id |
Account number (22-32) |
currency |
Currency (17-19), else the header's, else EUR |
amount |
The decoded amount, signed |
booking_date, value_date |
Operation date (35-40); value date (43-48), else the operation date |
description |
The label, then each 05 record's text, space-separated |
reference |
The entry number (82-88), or None when blank |
category |
cfonb:<interbank code>, or None when blank |
source, source_index |
"cfonb" and the operation's position in the file |
Amount and sign convention¶
An amount zone (91-104) is 13 digits and a final character that carries both the units digit and the sign. The digits are divided by 10 ** decimals (column 20 of the 01 header) as a decimal.Decimal, never a float.
| Final character | Units digit | Sign |
|---|---|---|
{ A B C D E F G H I |
0 to 9 | positive (credit) |
} J K L M N O P Q R |
0 to 9 | negative (debit) |
0-9 |
itself | positive |
So 0000000001904} with 2 decimals is -190.40. Characters other than ASCII digits elsewhere in the zone are skipped, and an empty zone is 0.
Errors¶
None of the functions raises on malformed CFONB text: a line that is not a record is skipped, a date that does not parse is None (a value date falls back to the operation date), and an amount keeps its ASCII digits. load_cfonb_file raises OSError when the file cannot be read; undecodable bytes are replaced, not refused.