From d41bc5e9b62ff145113a00044f822091e518dc95 2020-04-22 16:02:06 From: Brett Smith Date: 2020-04-22 16:02:06 Subject: [PATCH] reports: Add RelatedPostings.clear() method. --- diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index 1d271a707bb1e7bf98a796416bc55845b5c04020..3a0fbbebb918f76973158cc202919a1949be92ed 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -126,6 +126,9 @@ class RelatedPostings(Sequence[data.Posting]): def add(self, post: data.Posting) -> None: self._postings.append(post) + def clear(self) -> None: + self._postings.clear() + def iter_with_balance(self) -> Iterable[Tuple[data.Posting, Balance]]: balance = MutableBalance() for post in self: diff --git a/tests/test_reports_related_postings.py b/tests/test_reports_related_postings.py index f0bb60bf7ddb23e61732c7e4d47a9fa419f8c354..1848c0f29729b144502dec6dbb0d5b2fc691315a 100644 --- a/tests/test_reports_related_postings.py +++ b/tests/test_reports_related_postings.py @@ -78,6 +78,13 @@ def test_balance_credit_card(credit_card_cycle): assert related.balance() == testutil.balance_map(USD=expected) assert expected == 0 +def test_clear(): + related = core.RelatedPostings() + related.add(testutil.Posting('Income:Donations', -10)) + assert related.balance() + related.clear() + assert not related.balance() + def check_iter_with_balance(entries): expect_posts = [txn.postings[0] for txn in entries] expect_balances = []