From 677c99b565d8c5e3c83566e22f58ad9ff95494a3 2020-06-03 22:51:48 From: Brett Smith Date: 2020-06-03 22:51:48 Subject: [PATCH] accrual: Filter opening balance txn before main reporting. So far we've been implicitly relying on this by the user passing search terms that filter out the opening balance transaction. That will stop happening with the aging report, so we need to do it ourselves. --- diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 9b8255fbf8d48abe782117bbb85175cfc818c39d..eb6d372f8a1228dddfb94ab2c20ba16072ce6574 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -498,6 +498,7 @@ def main(arglist: Optional[Sequence[str]]=None, 'lineno': 1, } load_errors = [Error(source, "no books to load in configuration", None)] + filters.remove_opening_balance_txn(entries) postings = filter_search(data.Posting.from_entries(entries), args.search_terms) groups: PostGroups = dict(AccrualPostings.group_by_meta(postings, 'invoice')) groups = AccrualAccount.filter_paid_accruals(groups) or groups diff --git a/tests/books/accruals.beancount b/tests/books/accruals.beancount index 5be8a02be35a024ad2ec772c66efc5139657acc4..d538be0c023d487c08c2d23e8e555d48a6ea2516 100644 --- a/tests/books/accruals.beancount +++ b/tests/books/accruals.beancount @@ -5,6 +5,12 @@ 2020-01-01 open Expenses:Travel 2020-01-01 open Income:Donations 2020-01-01 open Liabilities:Payable:Accounts +2020-01-01 open Equity:Funds:Opening + +2020-03-01 * "Opening balances" + Equity:Funds:Opening -1000 USD + Assets:Receivable:Accounts 6000 USD + Liabilities:Payable:Accounts -5000 USD 2020-03-05 * "EarlyBird" "Payment for receivable from previous FY" rt-id: "rt:40" @@ -24,6 +30,13 @@ Liabilities:Payable:Accounts -75 USD Expenses:Travel 75 USD +2020-04-30 ! "Vendor" "Travel reimbursement" + rt-id: "rt:310" + contract: "rt:310/3100" + invoice: "FIXME" ; still waiting on them to send it + Liabilities:Payable:Accounts -200 USD + Expenses:Travel 200 USD + 2020-05-05 * "DonorA" "Donation pledge" rt-id: "rt:505" invoice: "rt:505/5050" diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 067fa393bcd60e80e7e7cef10eaa81cf961ec18a..bd64fc63c3edcebc09ac89c1dd69fbba944244b2 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -33,10 +33,15 @@ from conservancy_beancount.reports import accrual from conservancy_beancount.reports import core _accruals_load = bc_loader.load_file(testutil.test_path('books/accruals.beancount')) +ACCRUAL_TXNS = [ + entry for entry in _accruals_load[0] + if hasattr(entry, 'narration') + and entry.narration != 'Opening balances' +] ACCRUALS_COUNT = sum( 1 - for entry in _accruals_load[0] - for post in getattr(entry, 'postings', ()) + for txn in ACCRUAL_TXNS + for post in txn.postings if post.account.startswith(('Assets:Receivable:', 'Liabilities:Payable:')) ) @@ -74,14 +79,9 @@ class RTClient(testutil.RTClient): } -@pytest.fixture -def accrual_entries(): - return copy.deepcopy(_accruals_load[0]) - @pytest.fixture def accrual_postings(): - entries = copy.deepcopy(_accruals_load[0]) - return data.Posting.from_entries(entries) + return data.Posting.from_entries(copy.deepcopy(ACCRUAL_TXNS)) def check_link_regexp(regexp, match_s, first_link_only=False): assert regexp