The personal finance app for everyone (by everyone)
Ruby
Address all PR review comments
DataEnginr42a075a6db37
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rbindex 54adae2bfa..ce2447c56a 100644--- a/app/controllers/accounts_controller.rb+++ b/app/controllers/accounts_controller.rb@@ -106,9 +106,11 @@ class AccountsController < ApplicationControllerredirect_to accounts_pathend+ # Toggles the exclude_from_reports flag on the account and redirects to the+ # account list. The flag controls whether the account's data appears in+ # financial reports, dashboards, and exports.def toggle_exclude_from_reports- Account.where(id: @account.id).update_all("exclude_from_reports = NOT exclude_from_reports")- @account.reload+ @account.update!(exclude_from_reports: [email protected]_from_reports?)redirect_to accounts_pathenddiff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rbindex 2954e061e9..5701047216 100644--- a/app/controllers/reports_controller.rb+++ b/app/controllers/reports_controller.rb@@ -361,7 +361,8 @@ class ReportsController < ApplicationControllertransactions = Transaction.joins(:entry).joins(entry: :account)- .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ], exclude_from_reports: false })+ .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] })+ .merge(Account.included_in_reports).where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }).where.not(kind: Transaction::BUDGET_EXCLUDED_KINDS).includes(entry: :account, category: :parent)@@ -373,7 +374,8 @@ class ReportsController < ApplicationControllertrades = Trade.joins(:entry).joins(entry: :account)- .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ], exclude_from_reports: false })+ .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] })+ .merge(Account.included_in_reports).where(entries: { entryable_type: "Trade", excluded: false, date: @period.date_range }).includes(entry: :account, category: :parent)@@ -494,7 +496,8 @@ class ReportsController < ApplicationController# Eager-load security, account, and accountable to avoid N+1sell_trades = Current.family.trades.joins(entry: :account)- .where(entries: { date: @period.date_range }, accounts: { exclude_from_reports: [ false, nil ] })+ .where(entries: { date: @period.date_range })+ .merge(Account.included_in_reports).where("trades.qty < 0").includes(:security, entry: { account: :accountable }).to_a@@ -665,7 +668,8 @@ class ReportsController < ApplicationControllertransactions = Transaction.joins(:entry).joins(entry: :account)- .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ], exclude_from_reports: false })+ .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] })+ .merge(Account.included_in_reports).where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }).where.not(kind: Transaction::BUDGET_EXCLUDED_KINDS).includes(entry: :account, category: [])@@ -702,7 +706,8 @@ class ReportsController < ApplicationControllertransactions = Transaction.joins(:entry).joins(entry: :account)- .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ], exclude_from_reports: false })+ .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] })+ .merge(Account.included_in_reports).where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }).where.not(kind: Transaction::BUDGET_EXCLUDED_KINDS).includes(entry: :account, category: [])diff --git a/app/models/account.rb b/app/models/account.rbindex e2f99dc727..feb2c193d5 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -46,7 +46,9 @@ class Account < ApplicationRecordscope :visible, -> { where(status: VISIBLE_STATUSES) }scope :historical, -> { where(status: HISTORICAL_STATUSES) }- scope :included_in_reports, -> { where(exclude_from_reports: [ false, nil ]) }+ # Accounts whose data should be included in financial reports, dashboards,+ # and exports. Excludes accounts where the user has opted to suppress them.+ scope :included_in_reports, -> { where(exclude_from_reports: false) }scope :assets, -> { where(classification: "asset") }scope :liabilities, -> { where(classification: "liability") }scope :alphabetically, -> { order(:name) }diff --git a/app/models/balance_sheet/account_totals.rb b/app/models/balance_sheet/account_totals.rbindex 3bb1a8500d..a3769bf6d1 100644--- a/app/models/balance_sheet/account_totals.rb+++ b/app/models/balance_sheet/account_totals.rb@@ -19,6 +19,8 @@ class BalanceSheet::AccountTotalsAccountRow = Data.define(:account, :converted_balance, :is_syncing, :included_in_finances, :exclude_from_reports) dodef syncing? = is_syncingdef included_in_finances? = included_in_finances+ # Whether this account is excluded from financial reports, dashboards,+ # and exports.def exclude_from_reports? = exclude_from_reports# Allows Rails path helpers to generate URLs from the wrapperdiff --git a/db/migrate/20260609000000_add_exclude_from_reports_to_accounts.rb b/db/migrate/20260621000000_add_exclude_from_reports_to_accounts.rbsimilarity index 51%rename from db/migrate/20260609000000_add_exclude_from_reports_to_accounts.rbrename to db/migrate/20260621000000_add_exclude_from_reports_to_accounts.rbindex fabd58d34d..dd034649d1 100644--- a/db/migrate/20260609000000_add_exclude_from_reports_to_accounts.rb+++ b/db/migrate/20260621000000_add_exclude_from_reports_to_accounts.rb@@ -1,5 +1,5 @@class AddExcludeFromReportsToAccounts < ActiveRecord::Migration[8.1]def change- add_column :accounts, :exclude_from_reports, :boolean, default: false, null: false+ add_index :accounts, [:family_id, :exclude_from_reports]endenddiff --git a/db/schema.rb b/db/schema.rbindex bc6a5c5307..beb3d68fb4 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[8.1].define(version: 2026_06_17_120000) do+ActiveRecord::Schema[8.1].define(version: 2026_06_21_000000) do# These are extensions that must be enabled in order to support this databaseenable_extension "pg_catalog.plpgsql"enable_extension "pgcrypto"@@ -124,6 +124,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_06_17_120000) dot.index ["accountable_type"], name: "index_accounts_on_accountable_type"t.index ["currency"], name: "index_accounts_on_currency"t.index ["family_id", "accountable_type"], name: "index_accounts_on_family_id_and_accountable_type"+ t.index ["family_id", "exclude_from_reports"], name: "index_accounts_on_family_id_and_exclude_from_reports"t.index ["family_id", "id"], name: "index_accounts_on_family_id_and_id"t.index ["family_id", "status", "accountable_type"], name: "index_accounts_on_family_id_status_accountable_type"t.index ["family_id", "status"], name: "index_accounts_on_family_id_and_status"diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rbindex 890cb559d8..8ace6ec048 100644--- a/test/controllers/accounts_controller_test.rb+++ b/test/controllers/accounts_controller_test.rb@@ -301,6 +301,13 @@ class AccountsControllerTest < ActionDispatch::IntegrationTestassert_not @account.exclude_from_reports?end+ test "toggle_exclude_from_reports requires write permission" do+ sign_in users(:family_member)++ patch toggle_exclude_from_reports_account_url(accounts(:credit_card))+ assert_redirected_to account_url(accounts(:credit_card))+ end+test "select_provider shows available providers" doget select_provider_account_url(@account)assert_response :success