Skip to content

Commit

Permalink
fix(reconcile): handle balance and price entries in the ignored journ…
Browse files Browse the repository at this point in the history
…al file

Thanks to @Zburatorul for reporting.

Fixes #49
  • Loading branch information
jbms committed Jul 24, 2020
1 parent bd39126 commit 5ed8b00
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 3 deletions.
3 changes: 2 additions & 1 deletion beancount_import/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def _preprocess_entries(self):
for entry in self.editor.entries:
if isinstance(entry, Transaction):
posting_db.add_transaction(entry)
elif isinstance(entry, Price):
for entry in self.editor.all_entries:
if isinstance(entry, Price):
self.price_values.add((entry.date, entry.currency,
entry.amount))
elif isinstance(entry, Balance):
Expand Down
6 changes: 4 additions & 2 deletions beancount_import/reconcile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil

import py
import pytest
from beancount.core.data import Directive, Posting, Transaction

from . import reconcile
Expand Down Expand Up @@ -270,10 +271,11 @@ def test_ignore(tmpdir: py.path.local):
tester.accept_candidate(0, ignore=True)
tester.snapshot()

def test_ofx_basic(tmpdir: py.path.local):
@pytest.mark.parametrize('testdata_subdir', ['test_ofx_basic', 'test_ofx_ignore_balance', 'test_ofx_ignore_price'])
def test_ofx_basic(tmpdir: py.path.local, testdata_subdir: str):
tester = ReconcileGoldenTester(
golden_directory=os.path.join(testdata_root, 'reconcile',
'test_ofx_basic'),
testdata_subdir),
temp_dir=str(tmpdir),
options=dict(
data_sources=[
Expand Down
12 changes: 12 additions & 0 deletions testdata/reconcile/test_ofx_ignore_balance/0/candidates.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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 Assets:Retirement:Vanguard:Roth-IRA:TYCDT TYCDT
+
+2018-06-21 open Income:Vanguard:Dividends:TYCDT USD
1 change: 1 addition & 0 deletions testdata/reconcile/test_ofx_ignore_balance/0/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2018-07-03 balance Assets:Retirement:Vanguard:Roth-IRA:TYCDT 46.872 TYCDT
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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"
16 changes: 16 additions & 0 deletions testdata/reconcile/test_ofx_ignore_balance/0/pending.beancount
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; 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 price TYCDT 84.20 USD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
12 changes: 12 additions & 0 deletions testdata/reconcile/test_ofx_ignore_price/0/candidates.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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 Assets:Retirement:Vanguard:Roth-IRA:TYCDT TYCDT
+
+2018-06-21 open Income:Vanguard:Dividends:TYCDT USD
1 change: 1 addition & 0 deletions testdata/reconcile/test_ofx_ignore_price/0/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2018-07-03 price TYCDT 84.20 USD
8 changes: 8 additions & 0 deletions testdata/reconcile/test_ofx_ignore_price/0/journal.beancount
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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"
16 changes: 16 additions & 0 deletions testdata/reconcile/test_ofx_ignore_price/0/pending.beancount
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 5ed8b00

Please sign in to comment.