CAMT.53 statement import raises "Invalid isoformat string" if fraction of second is one digit only
When trying to import bank statements I get this error:
File "/trytond/modules/account_statement_sepa/account.py", line 102, in camt_statement_date
return dt.datetime.fromisoformat(datetime).date()
ValueError: Invalid isoformat string: '2024-03-14T22:04:41.0+01:00'
Fault: Invalid isoformat string: '2024-03-14T22:04:41.0+01:00'
The statement was created by a bank being member of German "Genossenschaftlicher Zahlungsverbund" (alliance of banking cooperatives of Germany), which is one of the three big players in Germany.
Analysis
-
dt.datetime.fromisoformat()
accepts supports strings in the formatYYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]
, which:- fraction of seconds for time, if given, is either 3 or 6 digits
- fraction of seconds for timezone, if given, is 6 digits
- separator for fraction of seconds is doc
-
The date-time string in the statement has a single digits for fraction of seconds for time.
-
The date-time string in the statement is standard compliant:
ISODateTime in ISO 20022 is defined with:
These representations are defined in "XML Schema Part 2: Datatypes Second Edition - W3C Recommendation 28 October 2004" which is aligned with ISO 8601.
…
Decimal fractions of seconds may be included. In this case, the involved parties shall agree on the maximum number of digits that are allowed.XML Schema Part 2: Datatypes Second Edition - W3C Recommendation 28 October 2004 defines (emphasis my me):
D.1 ISO 8601 Conventions
…
… the whole number of seconds ·may· be followed by decimal seconds to an arbitrary level of precision.and
3.2.7.1 Lexical representation
…
'.' s+ (if present) represents the fractional seconds;
Expected
- Dates with any number of digits for fraction of seconds are accepted
- Dates using both comma and dot as separator for fraction of seconds are accepted
Proposes solution
Use dateutil
to parse the date, as recommended by Python
Reproduce
- Install
account_statement_sepa
- Try importing the attached anonymized file 2024-03-21_C53_anonym.xml
- Experience the error