diff --git a/conservancy_beancount/books.py b/conservancy_beancount/books.py index 42bf434..3ed11c8 100644 --- a/conservancy_beancount/books.py +++ b/conservancy_beancount/books.py @@ -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: diff --git a/setup.py b/setup.py index 2099251..1cf9c85 100755 --- a/setup.py +++ b/setup.py @@ -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+', diff --git a/tests/books/2020-expenses.beancount b/tests/books/2020-expenses.beancount new file mode 100644 index 0000000..a192000 --- /dev/null +++ b/tests/books/2020-expenses.beancount @@ -0,0 +1,3 @@ +2020-04-02 * "2020 bank maintenance fee" + Expenses:BankingFees 1.00 USD + Assets:Checking diff --git a/tests/books/2020.beancount b/tests/books/2020-income.beancount similarity index 100% rename from tests/books/2020.beancount rename to tests/books/2020-income.beancount diff --git a/tests/books/books/2020.beancount b/tests/books/books/2020.beancount index 5097735..70ab960 100644 --- a/tests/books/books/2020.beancount +++ b/tests/books/books/2020.beancount @@ -1,3 +1,4 @@ option "title" "Books from 2020" include "../definitions.beancount" -include "../2020.beancount" +include "../2020-expenses.beancount" +include "../2020-income.beancount" diff --git a/tests/books/definitions.beancount b/tests/books/definitions.beancount index 3c833cc..443ead6 100644 --- a/tests/books/definitions.beancount +++ b/tests/books/definitions.beancount @@ -1,2 +1,3 @@ 2018-03-01 open Assets:Checking +2018-03-01 open Expenses:BankingFees 2018-03-01 open Income:Donations diff --git a/tests/test_reports_query.py b/tests/test_reports_query.py index 113407b..48efd66 100644 --- a/tests/test_reports_query.py +++ b/tests/test_reports_query.py @@ -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))