ofxparse icon indicating copy to clipboard operation
ofxparse copied to clipboard

Empty tags

Open sanderkruger opened this issue 10 years ago • 6 comments

My bank exports files with empty tags here and there, for example: <FI><ORG/><FID/></FI>

The empty tag syntax is valid XML but the parser doesn't like it. I can remove empty tags of course, but then I have to process all my bank statements. It would be much better if ofxparse sees the empty tag format and ignores the tags.

sanderkruger avatar Jun 11 '15 14:06 sanderkruger

After merging #108, the parser is more lenient. My guess is that this will go away. If you are able, could you check if this is still an issue?

nathangrigg avatar Oct 13 '16 02:10 nathangrigg

I continue to see similar issues with ofxparse 0.18.

My bank has exported an OFX file with the following empty fields: CHECKNUM, FITID, NAME, CURDEF, BRANCHID, ACCTTYPE, REFNUM

(Being new to OFX file formats, I'm not sure whether this is actually valid, and whether the bank is at fault, or ofxparse should handle the case more gracefully?)

The stacktrace is

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/hledger-autosync", line 11, in <module>
    sys.exit(run())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ledgerautosync/cli.py", line 311, in run
    import_ofx(ledger, args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ledgerautosync/cli.py", line 114, in import_ofx
    ofx = OfxSynchronizer.parse_file(args.PATH)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ledgerautosync/sync.py", line 41, in parse_file
    return OfxParser.parse(open(path))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 432, in parse
    ofx_obj.accounts += cls.parseStmtrs(stmtrs_ofx, AccountType.Bank)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 818, in parseStmtrs
    account.curdef = act_curdef.contents[0].strip()
IndexError: list index out of range

bruny avatar Aug 03 '18 11:08 bruny

Some unit tests would be helpful to check for this behavior. If I have time I'll create some.

jseutter avatar Aug 04 '18 17:08 jseutter

I can add the OFX files I'm using as test cases on a PR. 2 x separate OFX files from Australian banks, both using version 1.02 (SGML!).

bruny avatar Aug 05 '18 11:08 bruny

PR #143 added fixes for some elements, still some others to go.

bruny avatar Aug 09 '18 10:08 bruny

Two sample STMTTRN entries, both using v1.02 spec:

 <TRNTYPE>Credit</TRNTYPE>
 <DTPOSTED>20180801</DTPOSTED>
 <TRNAMT>0.0</TRNAMT>
 <FITID></FITID>
 <VALUEDATE>20180801</VALUEDATE>
 <NAME></NAME>
 <TRANSACTIONSPLIT>No</TRANSACTIONSPLIT>
 <CATEGORY>Uncategorised</CATEGORY>
 <ACCTBAL>-400.52</ACCTBAL>
 <CHECKNUM></CHECKNUM>
 <REFNUM></REFNUM>
 <MEMO>NEW INTEREST RATE  3.870%</MEMO>
 <CURRENCY>
  <CURRATE>1.0000</CURRATE>
  <CURSYM>AUD</CURSYM>
 </CURRENCY>
</STMTTRN>```

and

```<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20180801
<DTUSER>20180801
<TRNAMT>-10.00
<FITID>
<MEMO>Account Fee
</STMTTRN>```

Both have empty FITID fields. One has empty NAME field. Either empty or missing CHECKNUM and REFNUM fields.

Since transactions can be parsed by ofxparse if CHECKNUM, REFNAME, NAME and FITID are missing, empty fields should be handled in the same way.

Will try and put together a PR for these in the next few days.

bruny avatar Aug 09 '18 11:08 bruny