Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

present custom option value for list cfs on cost report

ulferts0a59cf172f28
diff --git a/modules/reporting/app/helpers/reporting_helper.rb b/modules/reporting/app/helpers/reporting_helper.rb
index aa284ec846d..ad36857bbb3 100644
--- a/modules/reporting/app/helpers/reporting_helper.rb
+++ b/modules/reporting/app/helpers/reporting_helper.rb
@@ -97,7 +97,8 @@ module ReportingHelper
end
def field_representation_map(key, value)
- return l(:label_none) if value.blank?
+ return t(:label_none) if value.blank?
+
case key.to_sym
when :activity_id then mapped value, Enumeration, "<i>#{l(:caption_material_costs)}</i>"
when :project_id then link_to_project Project.find(value.to_i)
@@ -116,12 +117,14 @@ module ReportingHelper
when :fixed_version_id then h(Version.find(value.to_i).name)
when :singleton_value then ''
when :status_id then h(Status.find(value.to_i).name)
+ when /custom_field\d+/ then CustomOption.find_by(id: value)&.value || value.to_s
else h(value.to_s)
end
end
def field_sort_map(key, value)
return '' if value.blank?
+
case key.to_sym
when :work_package_id, :tweek, :tmonth, :week then value.to_i
when :spent_on then value.to_date.mjd
diff --git a/modules/reporting/app/models/cost_query/custom_field_mixin.rb b/modules/reporting/app/models/cost_query/custom_field_mixin.rb
index fd3c118ffd6..be9c5dd4625 100644
--- a/modules/reporting/app/models/cost_query/custom_field_mixin.rb
+++ b/modules/reporting/app/models/cost_query/custom_field_mixin.rb
@@ -79,6 +79,7 @@ module CostQuery::CustomFieldMixin
def on_prepare(&block)
return factory.on_prepare unless factory?
+
@on_prepare = block if block
@on_prepare ||= proc {}
@on_prepare
@@ -163,6 +164,7 @@ module CostQuery::CustomFieldMixin
def new(*)
fail "Only subclasses of #{self} should be instanciated." if factory?
+
super
end
end
diff --git a/modules/reporting/spec/helpers/reporting_helper_spec.rb b/modules/reporting/spec/helpers/reporting_helper_spec.rb
new file mode 100644
index 00000000000..a91bc7bc2df
--- /dev/null
+++ b/modules/reporting/spec/helpers/reporting_helper_spec.rb
@@ -0,0 +1,61 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe ReportingHelper, type: :helper do
+ describe '#field_representation_map' do
+ context 'for a custom field' do
+ context 'for which a custom option exists (e.g. a list field)' do
+ it 'returns the option value' do
+ option = FactoryBot.build(:custom_option)
+
+ allow(CustomOption)
+ .to receive(:find_by)
+ .with(id: "345")
+ .and_return(option)
+
+ expect(field_representation_map("custom_field22", "345"))
+ .to eql option.value
+ end
+ end
+ end
+
+ context 'for which no custom option exists' do
+ it 'returns the option value' do
+ allow(CustomOption)
+ .to receive(:find_by)
+ .with(id: "345")
+ .and_return(nil)
+
+ expect(field_representation_map("custom_field22", "345"))
+ .to eql "345"
+ end
+ end
+ end
+end
diff --git a/modules/reporting_engine/lib/report/table.rb b/modules/reporting_engine/lib/report/table.rb
index be0963033ff..ebbe0c5261e 100644
--- a/modules/reporting_engine/lib/report/table.rb
+++ b/modules/reporting_engine/lib/report/table.rb
@@ -77,13 +77,16 @@ class Report::Table
def fields_for(type)
@fields_for ||= begin
- child, fields = query.chain, Hash.new { |h, k| h[k] = [] }
- until child.filter?
- fields[child.type].push(*child.group_fields)
- child = child.child
- end
- fields
- end
+ child = query.chain
+ fields = Hash.new { |h, k| h[k] = [] }
+
+ until child.filter?
+ fields[child.type].push(*child.group_fields)
+ child = child.child
+ end
+ fields
+ end
+
@fields_for[type]
end
@@ -94,6 +97,7 @@ class Report::Table
def with_gaps_for(type, result)
return enum_for(:with_gaps_for, type, result) unless block_given?
+
stack = get_index(type).dup
result.each_direct_result do |subresult|
yield nil until stack.empty? or satisfies? type, stack.shift, subresult
diff --git a/modules/reporting_engine/lib/widget/table/report_table.rb b/modules/reporting_engine/lib/widget/table/report_table.rb
index 32d8c78a473..fa94f9d2dae 100644
--- a/modules/reporting_engine/lib/widget/table/report_table.rb
+++ b/modules/reporting_engine/lib/widget/table/report_table.rb
@@ -102,6 +102,7 @@ class Widget::Table::ReportTable < Widget::Table
def render_thead
return if (walker.headers || true) and walker.headers_empty?
+
write '<thead>'
walker.headers do |list, first, first_in_col, last_in_col|
write '<tr>' if first_in_col