jseutter/ofxparse

Error parsing TRNAMT (should also accept commas)

turicas opened this issue · 2 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.

The fix needed is pretty simple -- just change the function that tries to parse the transaction amount on https://github.com/jseutter/ofxparse/blob/master/ofxparse/ofxparse.py#L824

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

I'm having the same issue with an OFX File from BNP Paribas Enterprises. I was extremely surprised to see that the spec says that you can use either dot or coma as decimal separator in OFX ! But the specs quotes of @turicas are right... so we have to also support coma as decimal separator :(

Thanks for solving the problem! :)