Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Do not include income transactions in liability accounts for savings rate (#1385)

Tony Vincent2b61821336ef
diff --git a/app/models/family.rb b/app/models/family.rb
index ddfdab3e..80f39275 100644
--- a/app/models/family.rb
+++ b/app/models/family.rb
@@ -71,7 +71,9 @@ class Family < ApplicationRecord
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 = []
diff --git a/test/models/family_test.rb b/test/models/family_test.rb
index 3b78401c..d56888ec 100644
--- a/test/models/family_test.rb
+++ b/test/models/family_test.rb
@@ -125,9 +125,11 @@ class FamilyTest < ActiveSupport::TestCase
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