Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

resolved the issues raised post pr

DataEnginr9723dc9e98b5
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 8dfee55c46..54adae2bfa 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: [email protected]_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 f0b9d7f147..2954e061e9 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 156e1ac387..1101df93e9 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