Skip to content

Commit

Permalink
Do not include income transactions in liability accounts for savings …
Browse files Browse the repository at this point in the history
…rate (#1385)

* Do not include income transactions in liability accounts for savings rate

* Do not include income in liability accounts in savings rate chart
  • Loading branch information
tonyvince authored Oct 31, 2024
1 parent 7946cd7 commit 2b61821
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/family.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def snapshot_account_transactions
end

def snapshot_transactions
candidate_entries = entries.account_transactions.without_transfers
candidate_entries = entries.account_transactions.without_transfers.excluding(
entries.joins(:account).where(amount: ..0, accounts: { classification: Account.classifications[:liability] })
)
rolling_totals = Account::Entry.daily_rolling_totals(candidate_entries, self.currency, period: Period.last_30_days)

spending = []
Expand Down
2 changes: 2 additions & 0 deletions test/models/family_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def setup

test "calculates rolling transaction totals" do
account = create_account(balance: 1000, accountable: Depository.new)
liability_account = create_account(balance: 1000, accountable: Loan.new)
create_transaction(account: account, date: 2.days.ago.to_date, amount: -500)
create_transaction(account: account, date: 1.day.ago.to_date, amount: 100)
create_transaction(account: account, date: Date.current, amount: 20)
create_transaction(account: liability_account, date: 2.days.ago.to_date, amount: -333)

snapshot = @family.snapshot_transactions

Expand Down

0 comments on commit 2b61821

Please sign in to comment.