Skip to content

Commit

Permalink
Handle chknum in transaction field
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic Chopin committed Nov 27, 2023
1 parent e62a8be commit 36d2146
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ofxparse/ofxparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,13 +1079,14 @@ def parseTransaction(cls, txn_ofx):
if cls.fail_fast:
raise

checknum_tag = txn_ofx.find('checknum')
if hasattr(checknum_tag, 'contents'):
try:
transaction.checknum = checknum_tag.contents[0].strip()
except IndexError:
raise OfxParserException(six.u("Empty Check (or other reference) \
number"))
for check_field in ('checknum', 'chknum'):
checknum_tag = txn_ofx.find(check_field)
if hasattr(checknum_tag, 'contents'):
try:
transaction.checknum = checknum_tag.contents[0].strip()
except IndexError:
raise OfxParserException(six.u("Empty Check (or other reference) \
number"))

return transaction

Expand Down
14 changes: 14 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ def testThatParseTransactionWithFieldCheckNum(self):
transaction = OfxParser.parseTransaction(txn.find('stmttrn'))
self.assertEqual('700', transaction.checknum)

def testThatParseTransactionWithFieldChknum(self):
input = '''
<STMTTRN>
<TRNTYPE>CHECK
<DTPOSTED>20231121
<TRNAMT>-113.71
<FITID>0000489
<CHKNUM>1932
</STMTTRN>
'''
txn = soup_maker(input)
transaction = OfxParser.parseTransaction(txn.find('stmttrn'))
self.assertEqual('1932', transaction.checknum)

def testThatParseTransactionWithCommaAsDecimalPoint(self):
input = '''
<STMTTRN>
Expand Down

0 comments on commit 36d2146

Please sign in to comment.