From 45e2f04d9e78356b070ef464a9ad1438156a8f7b Mon Sep 17 00:00:00 2001 From: soky srm Date: Mon, 10 Nov 2025 14:33:43 +0100 Subject: [PATCH] Fix Reports transactions breakdown (#309) The build_transactions_breakdown method was including ALL transaction types (including transfers, CC payments, and one-time transactions) when calculating the breakdown, while the "Period Comparison" and "Trends & Insights" sections correctly exclude these transaction types. --- app/controllers/reports_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 495b13dfd..2688d0b1e 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -304,11 +304,13 @@ class ReportsController < ApplicationController def build_transactions_breakdown # Base query: all transactions in the period + # Exclude transfers, one-time, and CC payments (matching income_statement logic) transactions = Transaction .joins(:entry) .joins(entry: :account) .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] }) .where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }) + .where.not(kind: [ "funds_movement", "one_time", "cc_payment" ]) .includes(entry: :account, category: []) # Apply filters @@ -397,11 +399,13 @@ class ReportsController < ApplicationController def build_transactions_breakdown_for_export # Get flat transactions list (not grouped) for export + # Exclude transfers, one-time, and CC payments (matching income_statement logic) transactions = Transaction .joins(:entry) .joins(entry: :account) .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] }) .where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }) + .where.not(kind: [ "funds_movement", "one_time", "cc_payment" ]) .includes(entry: :account, category: []) transactions = apply_transaction_filters(transactions) @@ -432,11 +436,13 @@ class ReportsController < ApplicationController end # Get all transactions in the period + # Exclude transfers, one-time, and CC payments (matching income_statement logic) transactions = Transaction .joins(:entry) .joins(entry: :account) .where(accounts: { family_id: Current.family.id, status: [ "draft", "active" ] }) .where(entries: { entryable_type: "Transaction", excluded: false, date: @period.date_range }) + .where.not(kind: [ "funds_movement", "one_time", "cc_payment" ]) .includes(entry: :account, category: []) transactions = apply_transaction_filters(transactions)