Skip to content

Commit

Permalink
Merge pull request #151 from chemtov/feature/add_dtuser
Browse files Browse the repository at this point in the history
Add user_date to the transaction object from the DTUSER field.
  • Loading branch information
jseutter authored Feb 5, 2020
2 parents c64d323 + b7a9b0a commit 3236cfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Here's a sample program
transaction.payee
transaction.type
transaction.date
transaction.user_date
transaction.amount
transaction.id
transaction.memo
Expand Down
14 changes: 14 additions & 0 deletions ofxparse/ofxparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def __init__(self):
self.payee = ''
self.type = ''
self.date = None
self.user_date = None
self.amount = None
self.id = ''
self.memo = ''
Expand Down Expand Up @@ -1033,6 +1034,19 @@ def parseTransaction(cls, txn_ofx):
raise OfxParserException(
six.u("Missing Transaction Date (a required field)"))

user_date_tag = txn_ofx.find('dtuser')
if hasattr(user_date_tag, "contents"):
try:
transaction.user_date = cls.parseOfxDateTime(
user_date_tag.contents[0].strip())
except IndexError:
raise OfxParserException("Invalid Transaction User Date")
except ValueError:
ve = sys.exc_info()[1]
raise OfxParserException(str(ve))
except TypeError:
pass

id_tag = txn_ofx.find('fitid')
if hasattr(id_tag, "contents"):
try:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def testThatParseTransactionReturnsATransaction(self):
input = '''
<STMTTRN>
<TRNTYPE>POS
<DTUSER>20090131
<DTPOSTED>20090401122017.000[-5:EST]
<TRNAMT>-6.60
<FITID>0000123456782009040100001
Expand All @@ -427,6 +428,7 @@ def testThatParseTransactionReturnsATransaction(self):
self.assertEqual('pos', transaction.type)
self.assertEqual(datetime(
2009, 4, 1, 12, 20, 17) - timedelta(hours=-5), transaction.date)
self.assertEqual(datetime(2009, 1, 31, 0, 0), transaction.user_date)
self.assertEqual(Decimal('-6.60'), transaction.amount)
self.assertEqual('0000123456782009040100001', transaction.id)
self.assertEqual("MCDONALD'S #112", transaction.payee)
Expand Down

0 comments on commit 3236cfd

Please sign in to comment.