From d23ede7afd8065f482fcb9d298c52558f18cc367 Mon Sep 17 00:00:00 2001 From: Alexander Bach Date: Tue, 24 Mar 2015 13:55:08 +0100 Subject: [PATCH] Fix custom field group sums --- .../api/experimental/concerns/column_data.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/experimental/concerns/column_data.rb b/app/controllers/api/experimental/concerns/column_data.rb index 7773e62220..43a5fe07e7 100644 --- a/app/controllers/api/experimental/concerns/column_data.rb +++ b/app/controllers/api/experimental/concerns/column_data.rb @@ -153,12 +153,25 @@ module Api::Experimental::Concerns::ColumnData # NOTE RS: This is basically the grouped_sums method from sums.rb but we # have no query to play with here return unless group_by + + if custom_field_id_in(group_by) + sum_columns(column_names, work_packages) do |wp| + wp.custom_values.detect { |cv| cv.custom_field_id == custom_field_id_in(group_by).to_i } + end + else + sum_columns(column_names, work_packages) do |wp| + wp.send(group_by) + end + end + end + + def sum_columns(column_names, work_packages) column_names.map do |column_name| - work_packages.map { |wp| wp.send(group_by) } + work_packages.map { |wp| yield wp } .uniq .inject({}) do |group_sums, current_group| work_packages_in_current_group = work_packages.select do |wp| - wp.send(group_by) == current_group + (yield wp) == current_group end group_sums.merge current_group => column_sum(column_name, work_packages_in_current_group)