Skip to content

Commit bed9baa

Browse files
author
Ludovic Chopin
committed
Handle chknum in transaction field
1 parent e62a8be commit bed9baa

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

ofxparse/ofxparse.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,14 @@ def parseTransaction(cls, txn_ofx):
10791079
if cls.fail_fast:
10801080
raise
10811081

1082-
checknum_tag = txn_ofx.find('checknum')
1083-
if hasattr(checknum_tag, 'contents'):
1084-
try:
1085-
transaction.checknum = checknum_tag.contents[0].strip()
1086-
except IndexError:
1087-
raise OfxParserException(six.u("Empty Check (or other reference) \
1088-
number"))
1082+
for check_field in ('checknum', 'chknum'):
1083+
checknum_tag = txn_ofx.find(check_field)
1084+
if hasattr(checknum_tag, 'contents'):
1085+
try:
1086+
transaction.checknum = checknum_tag.contents[0].strip()
1087+
except IndexError:
1088+
raise OfxParserException(six.u("Empty Check (or other reference) \
1089+
number"))
10891090

10901091
return transaction
10911092

tests/test_parse.py

+14
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@ def testThatParseTransactionWithFieldCheckNum(self):
449449
transaction = OfxParser.parseTransaction(txn.find('stmttrn'))
450450
self.assertEqual('700', transaction.checknum)
451451

452+
def testThatParseTransactionWithFieldChkNum(self):
453+
input = '''
454+
<STMTTRN>
455+
<TRNTYPE>CHECK
456+
<DTPOSTED>20231121
457+
<TRNAMT>-113.71
458+
<FITID>0000489
459+
<CHKNUM>1932
460+
</STMTTRN>
461+
'''
462+
txn = soup_maker(input)
463+
transaction = OfxParser.parseTransaction(txn.find('stmttrn'))
464+
self.assertEqual('1932', transaction.checknum)
465+
452466
def testThatParseTransactionWithCommaAsDecimalPoint(self):
453467
input = '''
454468
<STMTTRN>

0 commit comments

Comments
 (0)