Skip to content

Commit

Permalink
Adding a unit test for the Vanguard_529 importer
Browse files Browse the repository at this point in the history
  • Loading branch information
farktronix committed Sep 14, 2023
1 parent 94b3ef2 commit 0986ff8
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
2023-03-07 * "Investment Expense" "[V7743] Vanguard Target Retirement 2050 Trust"
Assets:Vanguard:401k:Pretax:V7743 -0.000349 V7743

2023-05-25 balance Assets:Vanguard:401k:V7743 113.718 V7743

2023-05-26 price V7743 117.71 USD

2023-05-27 balance Assets:Vanguard:401k:V7743 113.718 V7743
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Fund Account Number,Fund Name,Price,Shares,Total Value
535672845-01,Vanguard Target Enrollment 2040/2041 Portfolio,$9.45,348.5265,$3293.58

Account Number,Trade Date,Process Date,Transaction Type,Transaction Description,Investment Name,Share Price,Shares,Gross Amount,Net Amount
535672845-01,06/30/2023,06/30/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$9.51,26.2881,$250,$250
535672845-01,05/31/2023,05/31/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$9.01,27.7469,$250,$250
535672845-01,04/28/2023,04/28/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$9.11,27.4424,$250,$250
535672845-01,03/31/2023,03/31/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$9,27.7778,$250,$250
535672845-01,02/28/2023,02/28/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$8.76,28.5388,$250,$250
535672845-01,02/17/2023,02/17/2023,Contribution EBT,Contribution EBT,Vanguard Target Enrollment 2040/2041 Portfolio,$8.99,22.2469,$200,$200
535672845-01,01/31/2023,01/31/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$9.03,27.6855,$250,$250
535672845-01,01/03/2023,01/03/2023,Contribution AIP,Contribution AIP,Vanguard Target Enrollment 2040/2041 Portfolio,$8.42,29.6912,$250,$250
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

2023-01-03 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 29.6912 VTE2040 {8.42 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-01-31 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 27.6855 VTE2040 {9.03 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-02-17 * "Contribution EBT" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 22.2469 VTE2040 {8.99 USD}
Assets:Vanguard:529:Cash -200.00 USD

2023-02-28 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 28.5388 VTE2040 {8.76 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-03-31 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 27.7778 VTE2040 {9.00 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-04-28 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 27.4424 VTE2040 {9.11 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-05-31 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 27.7469 VTE2040 {9.01 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-06-30 * "Contribution AIP" "[VTE2040] Vanguard Target Enrollment 2040/2041 Portfolio"
Assets:Vanguard:529:VTE2040 26.2881 VTE2040 {9.51 USD}
Assets:Vanguard:529:Cash -250.00 USD

2023-06-30 price VTE2040 9.45 USD

2023-07-01 balance Assets:Vanguard:529:VTE2040 348.5265 VTE2040
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Assets:Vanguard:529
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-09-10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ofxdownload_09102023.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from os import path
from beancount.ingest import regression_pytest as regtest
from beancount_reds_importers.importers.vanguard import vanguard_529


@regtest.with_importer(
vanguard_529.Importer(
{
"account_number": "535672845-01",
"main_account": "Assets:Vanguard:529:{ticker}",
"cash_account": "Assets:Vanguard:529:Cash",
"dividends": "Income:Dividends:Vanguard:529:{ticker}",
"interest": "Income:Interest:Vanguard:529:{ticker}",
"cg": "Income:CapitalGains:529:{ticker}",
"capgainsd_lt": "Income:CapitalGains:Long:Vanguard:529:{ticker}",
"capgainsd_st": "Income:CapitalGains:Short:Vanguard:529:{ticker}",
"fees": "Expenses:Fees:Vanguard:529",
"invexpense": "Expenses:Expenses:Vanguard:529",
"rounding_error": "Equity:Rounding-Errors:Imports",
"fund_info": {
"fund_data": [
('VTE2040', '00000000', 'Vanguard Target Enrollment 2040/2041 Portfolio'),
],
"money_market": [],
},
"currency" : 'USD',
}
)
)
@regtest.with_testdir(path.dirname(__file__))
class TestVanguard529(regtest.ImporterTestBase):
pass
16 changes: 12 additions & 4 deletions beancount_reds_importers/importers/vanguard/vanguard_529.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import petl as etl
import sys
import re
import datetime
from datetime import datetime

from beancount.core.number import D

Expand Down Expand Up @@ -45,7 +45,15 @@ def deep_identify(self, file):
return super().deep_identify(file) and account_number in file.head()

def file_date(self, file):
return datetime.datetime.now()
date = None
# Use the date in the file name. If that doesn't exist, fall back to the maximum date we found in the transactions
match = re.search(r'\d{8}', file.name)
if match:
date_str = match.group()
date = datetime.strptime(date_str, "%m%d%Y").date()
else:
date = self.maxdate
return date

def prepare_tables(self):
ticker_by_desc = {desc: ticker for ticker, _, desc in self.fund_data}
Expand All @@ -62,11 +70,11 @@ def prepare_tables(self):
section = 'Transactions'
table = table.addfield('security', lambda x: ticker_by_desc.get(x['Investment Name'], x['Investment Name']))
# We have to do our own finding of the max date because the table data hasn't been cleaned up yet
maxdate = max(datetime.datetime.strptime(d[0], self.date_format) for d in table.cut('Trade Date').rename('Trade Date', 'date').namedtuples()).date().strftime(self.date_format)
self.maxdate = max(datetime.strptime(d[0], self.date_format) for d in table.cut('Trade Date').rename('Trade Date', 'date').namedtuples()).date().strftime(self.date_format)
alltables[section] = table
self.alltables = alltables

self.alltables['Balance Positions'] = self.alltables['Balance Positions'].addfield('date', maxdate)
self.alltables['Balance Positions'] = self.alltables['Balance Positions'].addfield('date', self.maxdate)

def is_section_title(self, row):
if len(row) == 0:
Expand Down

0 comments on commit 0986ff8

Please sign in to comment.