books: Let files under books/ include any Beancount files they want.

This provides more flexibility in repository setup while remaining backwards
compatible.

The changes to test_reports_query are just to accommodate the new
transaction in 2020-expenses.beancount.
This commit is contained in:
Brett Smith 2021-02-26 14:45:55 -05:00
parent 96b39a8778
commit 6752a40206
7 changed files with 15 additions and 6 deletions

View file

@ -24,6 +24,7 @@ from typing import (
Mapping,
NamedTuple,
Optional,
Set,
TextIO,
Union,
)
@ -177,16 +178,19 @@ class Loader:
result = LoadResult._make(bc_loader.load_file(next(paths)))
except StopIteration:
result = LoadResult.empty()
seen_files: Set[str] = set(result.options_map['include'])
for load_path in paths:
new_entries, new_errors, new_options = bc_loader.load_file(load_path)
# We only want transactions from the new fiscal year.
# We don't want the opening balance, duplicate definitions, etc.
fy_filename = str(load_path.parent.parent / load_path.name)
seen_files.add(new_options['filename'])
result.entries.extend(
entry for entry in new_entries
if entry.meta.get('filename') == fy_filename
if entry.meta.get('filename') not in seen_files
)
result.errors.extend(new_errors)
seen_files.update(new_options['include'])
result.options_map['include'] = list(seen_files)
return result
def _path_year(self, path: Path) -> int:

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup(
name='conservancy_beancount',
description="Plugin, library, and reports for reading Conservancy's books",
version='1.18.2',
version='1.18.3',
author='Software Freedom Conservancy',
author_email='info@sfconservancy.org',
license='GNU AGPLv3+',

View file

@ -0,0 +1,3 @@
2020-04-02 * "2020 bank maintenance fee"
Expenses:BankingFees 1.00 USD
Assets:Checking

View file

@ -1,3 +1,4 @@
option "title" "Books from 2020"
include "../definitions.beancount"
include "../2020.beancount"
include "../2020-expenses.beancount"
include "../2020-income.beancount"

View file

@ -1,2 +1,3 @@
2018-03-01 open Assets:Checking
2018-03-01 open Expenses:BankingFees
2018-03-01 open Income:Donations

View file

@ -183,7 +183,7 @@ def test_text_query(arglist, fy):
lines = iter(stdout)
next(lines); next(lines) # Skip header
for count, line in enumerate(lines, 1):
assert re.match(rf'^{fy}-\d\d-\d\d\s+{fy} donation\b', line)
assert re.match(rf'^{fy}-\d\d-\d\d\s+{fy} ', line)
assert count >= 2
@pytest.mark.parametrize('arglist,fy', testutil.combine_values(
@ -199,7 +199,7 @@ def test_csv_query(arglist, fy):
stdout.seek(0)
for count, row in enumerate(csv.DictReader(stdout), 1):
assert re.fullmatch(rf'{fy}-\d\d-\d\d', row['date'])
assert row['narration'] == f'{fy} donation'
assert row['narration'].startswith(f'{fy} ')
assert count >= 2
@pytest.mark.parametrize('end_index', range(3))