csingley/ofxtools

Error parsing TRNAMT (should also accept commas)

Closed this issue · 3 comments

Hello,

I have an OFX file generated by a Brazilian bank (Santander) - here we use "," as the decimal separator and the OFX have mixed "," and "." as decimal separators on the TRNAMT values (probably this difference occurs based on which integration they have, like the debit card or ATM systems).

Here is a sample:

<STMTTRN>
    <TRNTYPE>OTHER
    <DTPOSTED>20150706000000[-3:GMT]
    <TRNAMT>            -12.80
    <FITID>00451065
    <CHECKNUM>00451065
    <PAYEEID>0
    <MEMO>DEBITO VISA ELECTRON BRASIL        05/07 CAFE ALBRECHT L
</STMTTRN>
<STMTTRN>
    <TRNTYPE>OTHER
    <DTPOSTED>20150706000000[-3:GMT]
    <TRNAMT>           -200,00
    <FITID>00239183
    <CHECKNUM>00239183
    <PAYEEID>0
    <MEMO>SAQUE NO BANCO 24 HORAS
</STMTTRN>

I thought it was an error on the file (so Santander should fix it), but looking into the OFX specification I found that it's actually supported:

3.2.5 Transaction Amount <TRNAMT>
Format: Amount
Open Financial Exchange uses <TRNAMT> in any request or response that reports the total amount of an individual transaction.
Usage: Bank statement download, investment statement download, payments

And:

Amount: Amounts that do not represent whole numbers (for example, 540.32), must include a decimal point or comma to indicate the start of the fractional amount. Amounts should not include any punctuation separating thousands, millions, and so forth. The maximum value accepted depends on the client.

So, the "amount" types should not be represented by ofxtools.types.Decimal because it does not support commas as decimal separators. We should create another type to handle this properly or modify the ofxtools.types.Decimal to accept commas.

Note: I had the same error on the ofxparse library.

Yes, Euro-style decimal marks should definitely be supported. Let me review the most efficient fix & reply here.

Thanks for reporting.

OK checked in a quick fix in 3cb4ce7. Let me know if any further problems.

Tested here: the problem was fixed. Thanks a lot, @csingley! :)