From 9723dc9e98b5dfb1edcf06f773ff771f5cef6526 Mon Sep 17 00:00:00 2001 From: DataEnginr <23173570+DataEnginr@users.noreply.github.com> Date: Sat, 20 Jun 2026 20:17:17 +0000 Subject: [PATCH] resolved the issues raised post pr --- app/controllers/accounts_controller.rb | 3 ++- app/controllers/reports_controller.rb | 4 ++-- app/models/income_statement.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 8dfee55c4..54adae2bf 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -107,7 +107,8 @@ class AccountsController < ApplicationController end def toggle_exclude_from_reports - @account.update!(exclude_from_reports: !@account.exclude_from_reports) + Account.where(id: @account.id).update_all("exclude_from_reports = NOT exclude_from_reports") + @account.reload redirect_to accounts_path end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index f0b9d7f14..2954e061e 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -493,8 +493,8 @@ class ReportsController < ApplicationController # Get sell trades in period with realized gains # Eager-load security, account, and accountable to avoid N+1 sell_trades = Current.family.trades - .joins(:entry) - .where(entries: { date: @period.date_range }) + .joins(entry: :account) + .where(entries: { date: @period.date_range }, accounts: { exclude_from_reports: [ false, nil ] }) .where("trades.qty < 0") .includes(:security, entry: { account: :accountable }) .to_a diff --git a/app/models/income_statement.rb b/app/models/income_statement.rb index 156e1ac38..1101df93e 100644 --- a/app/models/income_statement.rb +++ b/app/models/income_statement.rb @@ -222,7 +222,7 @@ class IncomeStatement sql_hash = Digest::MD5.hexdigest(transactions_scope.to_sql) Rails.cache.fetch([ - "income_statement", "totals_query", "v2", family.id, user&.id, included_account_ids_hash, sql_hash, date_range.begin, date_range.end, family.entries_cache_version + "income_statement", "totals_query", "v2", family.id, user&.id, included_account_ids_hash, sql_hash, date_range.begin, date_range.end, family.entries_cache_version, family.accounts.maximum(:updated_at)&.to_i ]) { Totals.new(family, transactions_scope: transactions_scope, date_range: date_range, included_account_ids: included_account_ids).call } end