Files
sure/app/models/investment_flow_statement.rb
panther eb0866a678 Add exclude_from_reports option to accounts
Adds a toggle to mark accounts as excluded from all financial reports
while keeping them active and visible individually.

- Migration: add exclude_from_reports boolean column to accounts
- Model: included_in_reports scope
- BalanceSheet: filter excluded from ClassificationGroup and AccountGroup totals,
  HistoricalAccountScope, AccountRow flag
- IncomeStatement: exclude via SQL fragments in Totals, FamilyStats, CategoryStats
- InvestmentStatement/Budget: chain included_in_reports scope
- ReportsController: filter in breakdown view, export queries, trades
- AccountsController: toggle_exclude_from_reports action + route
- UI: DS::Toggle in account form, eye-off indicator in sidebar, menu toggle items
- Locale: all labels in en.yml
- Tests: model scope, controller toggle, income statement/balance sheet filtering
- 5070 tests pass (0 failures, 0 regressions)
2026-06-27 00:57:03 +00:00

49 lines
1.5 KiB
Ruby

class InvestmentFlowStatement
include Monetizable
CONTRIBUTIONS_TOTAL_SQL = Arel.sql(
"COALESCE(ABS(SUM(CASE WHEN transactions.investment_activity_label = 'Contribution' " \
"THEN entries.amount ELSE 0 END)), 0)"
)
WITHDRAWALS_TOTAL_SQL = Arel.sql(
"COALESCE(ABS(SUM(CASE WHEN transactions.investment_activity_label = 'Withdrawal' " \
"THEN entries.amount ELSE 0 END)), 0)"
)
private_constant :CONTRIBUTIONS_TOTAL_SQL, :WITHDRAWALS_TOTAL_SQL
attr_reader :family, :user
def initialize(family, user: nil)
@family = family
@user = user
end
# Get contribution/withdrawal totals for a period
def period_totals(period: Period.current_month)
scope = family.transactions
.visible
.excluding_pending
.where(entries: { date: period.date_range })
.where(kind: %w[standard investment_contribution])
.where(investment_activity_label: %w[Contribution Withdrawal])
if user
account_ids = family.accounts.included_in_finances_for(user).included_in_reports.select(:id)
scope = scope.where(entries: { account_id: account_ids })
end
contributions, withdrawals = scope.pick(
CONTRIBUTIONS_TOTAL_SQL,
WITHDRAWALS_TOTAL_SQL
)
PeriodTotals.new(
contributions: Money.new(contributions, family.currency),
withdrawals: Money.new(withdrawals, family.currency),
net_flow: Money.new(contributions - withdrawals, family.currency)
)
end
PeriodTotals = Data.define(:contributions, :withdrawals, :net_flow)
end