reports: Add RelatedPostings.clear() method.

This commit is contained in:
Brett Smith 2020-04-22 12:02:06 -04:00
parent ed4258daf7
commit d41bc5e9b6
2 changed files with 10 additions and 0 deletions

View file

@ -126,6 +126,9 @@ class RelatedPostings(Sequence[data.Posting]):
def add(self, post: data.Posting) -> None: def add(self, post: data.Posting) -> None:
self._postings.append(post) self._postings.append(post)
def clear(self) -> None:
self._postings.clear()
def iter_with_balance(self) -> Iterable[Tuple[data.Posting, Balance]]: def iter_with_balance(self) -> Iterable[Tuple[data.Posting, Balance]]:
balance = MutableBalance() balance = MutableBalance()
for post in self: for post in self:

View file

@ -78,6 +78,13 @@ def test_balance_credit_card(credit_card_cycle):
assert related.balance() == testutil.balance_map(USD=expected) assert related.balance() == testutil.balance_map(USD=expected)
assert expected == 0 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): def check_iter_with_balance(entries):
expect_posts = [txn.postings[0] for txn in entries] expect_posts = [txn.postings[0] for txn in entries]
expect_balances = [] expect_balances = []