diff --git a/app/models/queries/work_packages/selects/work_package_select.rb b/app/models/queries/work_packages/selects/work_package_select.rb index f52df5347d9f..90ed98e5f530 100644 --- a/app/models/queries/work_packages/selects/work_package_select.rb +++ b/app/models/queries/work_packages/selects/work_package_select.rb @@ -54,12 +54,10 @@ def self.scoped_column_sum(scope, select, grouped:, query:) scope = scope.except(:order, :select) if grouped - group_by = query.group_by_statement - scope .joins(query.group_by_join_statement) - .group(group_by) - .select(select_group_by(group_by), select) + .group(query.group_by_statement) + .select(select_group_by(query.group_by_select), select) else scope .select(select) diff --git a/app/models/query/results/sums.rb b/app/models/query/results/sums.rb index 27e735d4f204..d349e199f2f9 100644 --- a/app/models/query/results/sums.rb +++ b/app/models/query/results/sums.rb @@ -109,7 +109,7 @@ def sums_callable_joins(grouped) def sums_work_package_scope_selects(grouped) group_statement = if grouped - [Queries::WorkPackages::Selects::WorkPackageSelect.select_group_by(query.group_by_statement)] + [Queries::WorkPackages::Selects::WorkPackageSelect.select_group_by(query.group_by_select)] else [] end diff --git a/modules/costs/spec/lib/costs/query_currency_select_spec.rb b/modules/costs/spec/lib/costs/query_currency_select_spec.rb index 26ecf739d7de..8139e7f1c884 100644 --- a/modules/costs/spec/lib/costs/query_currency_select_spec.rb +++ b/modules/costs/spec/lib/costs/query_currency_select_spec.rb @@ -93,6 +93,7 @@ allow(query).to receive_messages( results: result, group_by_join_statement: nil, + group_by_select: "author_id", group_by_statement: "author_id" ) @@ -130,6 +131,7 @@ allow(query).to receive_messages( results: result, group_by_join_statement: nil, + group_by_select: "author_id", group_by_statement: "author_id" )