Skip to content

Commit

Permalink
Fix Account.daily_balance cleared filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhannah committed Jan 22, 2025
1 parent 674bd6b commit c4e5e73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/budge/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def daily_balance(
given, the date of the first transaction is used. If the end date is not
given, today's date is used.
"""
start_date = start_date or next(self.transactions_range()).date
start_date = start_date or next(self.transactions_range(cleared=cleared)).date
end_date = end_date or date.today()

balance = self.balance(start_date, cleared)
Expand Down
22 changes: 22 additions & 0 deletions tests/budge/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,25 @@ def test_account_daily_balance_future(account: Account, today: date):
assert balances[9] == (date(2022, 12, 15), Money(2))
assert balances[11] == (date(2022, 12, 17), Money(4))
assert balances[-1] == (end_date, Money(5))


def test_account_daily_balance_cleared_true(account: Account, today: date):
end_date = today + relativedelta(months=1)
balances = list(account.daily_balance(today, end_date, cleared=True))

assert len(balances) == 32
assert balances[0] == (today, Money(1))
assert balances[9] == (date(2022, 12, 15), Money(1))
assert balances[11] == (date(2022, 12, 17), Money(3))
assert balances[-1] == (end_date, Money(3))


def test_account_daily_balance_cleared_false(account: Account, today: date):
end_date = today + relativedelta(months=1)
balances = list(account.daily_balance(today, end_date, cleared=False))

assert len(balances) == 32
assert balances[0] == (today, Money(1))
assert balances[9] == (date(2022, 12, 15), Money(1))
assert balances[11] == (date(2022, 12, 17), Money(1))
assert balances[-1] == (end_date, Money(2))

0 comments on commit c4e5e73

Please sign in to comment.