diff --git a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx similarity index 100% rename from beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx rename to beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx diff --git a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.extract b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.extract similarity index 94% rename from beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.extract rename to beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.extract index eb71d94..7c88a20 100644 --- a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.extract +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.extract @@ -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 diff --git a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_account b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_account similarity index 100% rename from beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_account rename to beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_account diff --git a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_date b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_date similarity index 100% rename from beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_date rename to beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_date diff --git a/beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_name b/beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_name similarity index 100% rename from beancount_reds_importers/importers/vanguard/tests/OfxDownload-401k.qfx.file_name rename to beancount_reds_importers/importers/vanguard/tests/vanguard/OfxDownload-401k.qfx.file_name diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_test.py b/beancount_reds_importers/importers/vanguard/tests/vanguard/vanguard_test.py similarity index 100% rename from beancount_reds_importers/importers/vanguard/tests/vanguard_test.py rename to beancount_reds_importers/importers/vanguard/tests/vanguard/vanguard_test.py diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv new file mode 100644 index 0000000..f14224a --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv @@ -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 diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.extract b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.extract new file mode 100644 index 0000000..893b2a0 --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.extract @@ -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 diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_account b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_account new file mode 100644 index 0000000..e2db6d4 --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_account @@ -0,0 +1 @@ +Assets:Vanguard:529 diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_date b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_date new file mode 100644 index 0000000..6253d73 --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_date @@ -0,0 +1 @@ +2023-09-10 diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_name b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_name new file mode 100644 index 0000000..58d8e49 --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/ofxdownload_09102023.csv.file_name @@ -0,0 +1 @@ +ofxdownload_09102023.csv diff --git a/beancount_reds_importers/importers/vanguard/tests/vanguard_529/vanguard_529_test.py b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/vanguard_529_test.py new file mode 100644 index 0000000..89775bc --- /dev/null +++ b/beancount_reds_importers/importers/vanguard/tests/vanguard_529/vanguard_529_test.py @@ -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 diff --git a/beancount_reds_importers/importers/vanguard/vanguard_529.py b/beancount_reds_importers/importers/vanguard/vanguard_529.py index 9bb1da2..2adc9c4 100644 --- a/beancount_reds_importers/importers/vanguard/vanguard_529.py +++ b/beancount_reds_importers/importers/vanguard/vanguard_529.py @@ -3,7 +3,7 @@ import petl as etl import sys import re -import datetime +from datetime import datetime from beancount.core.number import D @@ -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} @@ -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: