Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reconcile): support cleared_* on parent accounts #38

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion beancount_import/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _get_uncleared_postings(self):
parts = account_name.split(':')
cleared_before = datetime.date.min
cleared_after = datetime.date.max
for part_i in range(1, len(parts) - 1):
for part_i in range(1, len(parts)):
ancestor_account_name = ':'.join(parts[:part_i])
ancestor_cleared_dates = cleared_dates.get(ancestor_account_name)
if ancestor_cleared_dates is None: continue
Expand Down
35 changes: 22 additions & 13 deletions beancount_import/reconcile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self,
self.temp_dir = temp_dir
self.replacements = [
(os.path.realpath(temp_dir), '<journal-dir>'),
(testdata_root, '<testdata>'),
*replacements,
]
self.write = write
Expand Down Expand Up @@ -198,7 +199,7 @@ def _check_state(self, snapshot_name: str):
write=self.write,
)
for filename, expected_contents in _add_invalid_reference_and_uncleared_metadata(
loaded_reconciler):
loaded_reconciler).items():
test_util.check_golden_contents(
path=filename,
expected_contents=expected_contents,
Expand Down Expand Up @@ -230,9 +231,6 @@ def test_basic(tmpdir: py.path.local):
tester = ReconcileGoldenTester(
golden_directory=os.path.join(testdata_root, 'reconcile', 'test_basic'),
temp_dir=str(tmpdir),
replacements=[
(testdata_root, '<testdata>'),
],
options=dict(
data_sources=[
{
Expand All @@ -255,9 +253,6 @@ def test_ignore(tmpdir: py.path.local):
golden_directory=os.path.join(testdata_root, 'reconcile',
'test_ignore'),
temp_dir=str(tmpdir),
replacements=[
(testdata_root, '<testdata>'),
],
options=dict(
data_sources=[
{
Expand All @@ -280,9 +275,6 @@ def test_ofx_basic(tmpdir: py.path.local):
golden_directory=os.path.join(testdata_root, 'reconcile',
'test_ofx_basic'),
temp_dir=str(tmpdir),
replacements=[
(testdata_root, '<testdata>'),
],
options=dict(
data_sources=[
{
Expand All @@ -302,9 +294,26 @@ def test_ofx_matching(tmpdir: py.path.local):
golden_directory=os.path.join(testdata_root, 'reconcile',
'test_ofx_matching'),
temp_dir=str(tmpdir),
replacements=[
(testdata_root, '<testdata>'),
],
options=dict(
data_sources=[
{
'module':
'beancount_import.source.ofx',
'ofx_filenames': [
os.path.join(testdata_root, 'source', 'ofx',
'vanguard_roth_ira.ofx')
],
},
],
),
)


def test_ofx_cleared(tmpdir: py.path.local):
tester = ReconcileGoldenTester(
golden_directory=os.path.join(testdata_root, 'reconcile',
'test_ofx_cleared'),
temp_dir=str(tmpdir),
options=dict(
data_sources=[
{
Expand Down
10 changes: 10 additions & 0 deletions testdata/reconcile/test_ofx_cleared/0/candidates.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<journal-dir>/journal.beancount
+
+2018-06-21 * "REINVEST - DIV"
+ Assets:Retirement:Vanguard:Roth-IRA:TYCDT 31.704 TYCDT {2.94 USD}
+ date: 2018-06-21
+ ofx_fitid: "7c9254b784a.a9bd.edcfa27b.b"
+ ofx_type: "REINVEST"
+ Income:Vanguard:Dividends:TYCDT -93.21 USD
+
+2018-06-21 open Income:Vanguard:Dividends:TYCDT USD
1 change: 1 addition & 0 deletions testdata/reconcile/test_ofx_cleared/0/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
20 changes: 20 additions & 0 deletions testdata/reconcile/test_ofx_cleared/0/journal.beancount
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugin "beancount.plugins.auto_accounts"

1900-01-01 open Assets:Retirement:Vanguard:Roth-IRA
ofx_org: "MyBank"
ofx_broker_id: "MyBank"
ofx_account_type: "securities_only"
account_id: "123456789"
div_income_account: "Income:Vanguard:Dividends"
cleared_before: 2018-01-01

1900-01-01 open Assets:Retirement:Vanguard:Roth-IRA:TYCDT TYCDT

2017-12-31 * "Opening Balance"
Assets:Retirement:Vanguard:Roth-IRA:TYCDT 10.168 TYCDT { 79.22 USD }
Equity:Opening-Balances

2018-01-01 * "Mysterious gift"
Assets:Retirement:Vanguard:Roth-IRA:TYCDT 5.000 TYCDT { 79.30 USD }
uncleared: TRUE
Equity:Opening-Balances
18 changes: 18 additions & 0 deletions testdata/reconcile/test_ofx_cleared/0/pending.beancount
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;; source: ofx
;; date: 2018-06-21
;; info: {"filename": "<testdata>/source/ofx/vanguard_roth_ira.ofx", "type": "application/x-ofx"}

2018-06-21 * "REINVEST - DIV"
Assets:Retirement:Vanguard:Roth-IRA:TYCDT 31.704 TYCDT {2.94 USD}
date: 2018-06-21
ofx_fitid: "7c9254b784a.a9bd.edcfa27b.b"
ofx_type: "REINVEST"
Income:Vanguard:Dividends:TYCDT -93.21 USD

;; source: ofx
;; date: 2018-07-03
;; info: null

2018-07-03 balance Assets:Retirement:Vanguard:Roth-IRA:TYCDT 46.872 TYCDT

2018-07-03 price TYCDT 84.20 USD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]