The personal finance app for everyone (by everyone)
Ruby
Exclude report-excluded accounts from paycheck cash (#5822)
Devaughn Walkerd00b21f016c4
diff --git a/app/models/recurring_transaction/paycheck_planner.rb b/app/models/recurring_transaction/paycheck_planner.rbindex be2752464c..d3fa6c6792 100644--- a/app/models/recurring_transaction/paycheck_planner.rb+++ b/app/models/recurring_transaction/paycheck_planner.rb@@ -273,7 +273,7 @@ class RecurringTransaction# Cash a bill can actually be paid from before the next paycheck: the# family's own deposit accounts, minus the tax-advantaged ones nobody- # spends rent out of. Credit cards share the `:cash` balance type but are+ # spends rent out of and the ones excluded from reports. Credit cards share the `:cash` balance type but are# a liability, so they are not money on hand.## nil, never zero, when there is nothing to read. Zero would assert the@@ -282,7 +282,7 @@ class RecurringTransactiondef cash_on_handreturn @cash_on_hand if defined?(@cash_on_hand)- accounts = family.accounts.visible+ accounts = family.accounts.visible.included_in_reports.where(accountable_type: "Depository").merge(Account.accessible_by(user))diff --git a/test/models/recurring_transaction/paycheck_planner_test.rb b/test/models/recurring_transaction/paycheck_planner_test.rbindex df43a77033..ac1f9b3c78 100644--- a/test/models/recurring_transaction/paycheck_planner_test.rb+++ b/test/models/recurring_transaction/paycheck_planner_test.rb@@ -470,6 +470,18 @@ class RecurringTransaction::PaycheckPlannerTest < ActiveSupport::TestCaseassert_equal 436, bridge.cash_after_obligationsend+ test "accounts excluded from reports are not cash on hand" do+ set_cash(500)+ @family.accounts.create!(name: "Someone else's checking", balance: 10_000, currency: "USD",+ exclude_from_reports: true, accountable: Depository.new)+ create_series(name: "Paycheck", amount: -1840, due: Date.current + 5, preset: "weekly", income: true)+ create_series(name: "Water", amount: 64, due: Date.current + 2)++ bridge = Planner.new(@family, user: @user).plan(periods_limit: 3).first++ assert_equal 500, bridge.cash_on_hand, "the excluded account's balance is not counted"+ end+test "an unknown balance is not evidence of a shortfall" do@family.accounts.update_all(status: "disabled")create_series(name: "Paycheck", amount: -1840, due: Date.current + 5, preset: "weekly", income: true)