mirror of
https://github.com/we-promise/sure.git
synced 2026-07-15 14:25:21 +00:00
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)
64 lines
2.1 KiB
Ruby
64 lines
2.1 KiB
Ruby
class BalanceSheet::ClassificationGroup
|
|
include Monetizable
|
|
|
|
monetize :total, as: :total_money
|
|
|
|
attr_reader :classification, :currency
|
|
|
|
def initialize(classification:, currency:, accounts:)
|
|
@classification = normalize_classification!(classification)
|
|
@name = name
|
|
@currency = currency
|
|
@accounts = accounts
|
|
end
|
|
|
|
def name
|
|
I18n.t("pages.dashboard.balance_sheet.classifications.#{classification}", default: classification.titleize.pluralize)
|
|
end
|
|
|
|
def icon
|
|
classification == "asset" ? "plus" : "minus"
|
|
end
|
|
|
|
def total
|
|
accounts.select { |a| a.respond_to?(:included_in_finances?) ? a.included_in_finances? : true }
|
|
.reject { |a| a.respond_to?(:exclude_from_reports?) && a.exclude_from_reports? }
|
|
.sum(&:converted_balance)
|
|
end
|
|
|
|
def syncing?
|
|
accounts.any?(&:syncing?)
|
|
end
|
|
|
|
# For now, we group by accountable type. This can be extended in the future to support arbitrary user groupings.
|
|
def account_groups
|
|
groups = accounts.group_by(&:accountable_type)
|
|
.transform_keys { |at| Accountable.from_type(at) }
|
|
.map do |accountable, account_rows|
|
|
BalanceSheet::AccountGroup.new(
|
|
name: accountable.display_name,
|
|
color: accountable.color,
|
|
accountable_type: accountable,
|
|
accounts: account_rows,
|
|
classification_group: self
|
|
)
|
|
end
|
|
|
|
# Sort the groups using the manual order defined by Accountable::TYPES so that
|
|
# the UI displays account groups in a predictable, domain-specific sequence.
|
|
groups.sort_by do |group|
|
|
manual_order = Accountable::TYPES
|
|
type_name = group.key.camelize
|
|
manual_order.index(type_name) || Float::INFINITY
|
|
end
|
|
end
|
|
|
|
private
|
|
attr_reader :accounts
|
|
|
|
def normalize_classification!(classification)
|
|
raise ArgumentError, "Invalid classification: #{classification}" unless %w[asset liability].include?(classification)
|
|
classification
|
|
end
|
|
end
|