Skip to content

Commit 3236cfd

Browse files
authored
Merge pull request #151 from chemtov/feature/add_dtuser
Add user_date to the transaction object from the DTUSER field.
2 parents c64d323 + b7a9b0a commit 3236cfd

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Here's a sample program
7373
transaction.payee
7474
transaction.type
7575
transaction.date
76+
transaction.user_date
7677
transaction.amount
7778
transaction.id
7879
transaction.memo

ofxparse/ofxparse.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def __init__(self):
312312
self.payee = ''
313313
self.type = ''
314314
self.date = None
315+
self.user_date = None
315316
self.amount = None
316317
self.id = ''
317318
self.memo = ''
@@ -1033,6 +1034,19 @@ def parseTransaction(cls, txn_ofx):
10331034
raise OfxParserException(
10341035
six.u("Missing Transaction Date (a required field)"))
10351036

1037+
user_date_tag = txn_ofx.find('dtuser')
1038+
if hasattr(user_date_tag, "contents"):
1039+
try:
1040+
transaction.user_date = cls.parseOfxDateTime(
1041+
user_date_tag.contents[0].strip())
1042+
except IndexError:
1043+
raise OfxParserException("Invalid Transaction User Date")
1044+
except ValueError:
1045+
ve = sys.exc_info()[1]
1046+
raise OfxParserException(str(ve))
1047+
except TypeError:
1048+
pass
1049+
10361050
id_tag = txn_ofx.find('fitid')
10371051
if hasattr(id_tag, "contents"):
10381052
try:

tests/test_parse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ def testThatParseTransactionReturnsATransaction(self):
415415
input = '''
416416
<STMTTRN>
417417
<TRNTYPE>POS
418+
<DTUSER>20090131
418419
<DTPOSTED>20090401122017.000[-5:EST]
419420
<TRNAMT>-6.60
420421
<FITID>0000123456782009040100001
@@ -427,6 +428,7 @@ def testThatParseTransactionReturnsATransaction(self):
427428
self.assertEqual('pos', transaction.type)
428429
self.assertEqual(datetime(
429430
2009, 4, 1, 12, 20, 17) - timedelta(hours=-5), transaction.date)
431+
self.assertEqual(datetime(2009, 1, 31, 0, 0), transaction.user_date)
430432
self.assertEqual(Decimal('-6.60'), transaction.amount)
431433
self.assertEqual('0000123456782009040100001', transaction.id)
432434
self.assertEqual("MCDONALD'S #112", transaction.payee)

0 commit comments

Comments
 (0)