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

cost query - filter by cf value but return id

ulferts90a53a0aad8d
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 a0e34d72542..117f37852cf 100644
--- a/modules/reporting/app/models/cost_query/custom_field_mixin.rb
+++ b/modules/reporting/app/models/cost_query/custom_field_mixin.rb
@@ -122,7 +122,8 @@ module CostQuery::CustomFieldMixin
-- BEGIN Custom Field Join: #{cf_name}
LEFT OUTER JOIN (
SELECT
- CAST(co.value AS #{cast_as}) AS #{cf_name},
+ co.id AS #{cf_name},
+ co.value,
cv.customized_type,
cv.custom_field_id,
cv.customized_id
diff --git a/modules/reporting/app/models/cost_query/filter/custom_field_entries.rb b/modules/reporting/app/models/cost_query/filter/custom_field_entries.rb
index f75bcd5c70d..e30f71103b7 100644
--- a/modules/reporting/app/models/cost_query/filter/custom_field_entries.rb
+++ b/modules/reporting/app/models/cost_query/filter/custom_field_entries.rb
@@ -45,6 +45,21 @@ class CostQuery::Filter::CustomFieldEntries < Report::Filter::Base
end
end
+ def self.field
+ # There is a special treatment for how list custom values are retrieved as those
+ # are not taken directly from the custom_values but from the custom_options table.
+ # But the value still has to be the id of the option which is later on mapped to the
+ # human readable value.
+ # Mapping to the human readable value is done for all custom values (e.g. users, versions)
+ # following the same pattern of code, so simply making the exception here to use the value
+ # would complicated the code later on.
+ if custom_field.field_format == 'list'
+ "#{db_field}.value"
+ else
+ super
+ end
+ end
+
def self.available_values(*)
@possible_values || get_possible_values
end
diff --git a/modules/reporting/spec/features/custom_fields_spec.rb b/modules/reporting/spec/features/custom_fields_spec.rb
index be44dc04195..13c1e97ab3c 100644
--- a/modules/reporting/spec/features/custom_fields_spec.rb
+++ b/modules/reporting/spec/features/custom_fields_spec.rb
@@ -105,7 +105,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
# Expect empty result table
within('#result-table') do
- expect(page).to have_no_selector('.top.result', text: '12.50 hours')
+ expect(page).not_to have_selector('.top.result', text: '12.50 hours')
end
expect(page).to have_selector('.generic-table--no-results-title')
@@ -132,8 +132,9 @@ describe 'Custom fields reporting', type: :feature, js: true do
# Expect row of work package
within('#result-table') do
expect(page).to have_selector('a.work_package', text: "#{work_package.type} ##{work_package.id}")
- expect(page).to have_selector('th.inner', text: 'First option')
- expect(page).to have_no_selector('th.inner', text: 'Second option')
+ # There used to be additional and unwanted text after the option name being rendered.
+ expect(page).to have_selector('th.inner', text: /^First option$/)
+ expect(page).not_to have_selector('th.inner', text: 'Second option')
# Only first option should have content for the work package
expect(page).to have_selector('table.report tbody tr', count: 1)
@@ -195,7 +196,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
within('#result-table') do
expect(page).to have_selector('a.work_package', text: "#{work_package.type} ##{work_package.id}")
expect(page).to have_selector('th.inner', text: '1')
- expect(page).to have_no_selector('th.inner', text: 'invalid!')
+ expect(page).not_to have_selector('th.inner', text: 'invalid!')
end
end
end
@@ -228,7 +229,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
within('#result-table') do
expect(page).to have_selector('a.work_package', text: "#{work_package.type} ##{work_package.id}")
expect(page).to have_selector('th.inner', text: 'foo')
- expect(page).to have_no_selector('th.inner', text: 'None')
+ expect(page).not_to have_selector('th.inner', text: 'None')
# Only first option should have content for the work package
expect(page).to have_selector('table.report tbody tr', count: 1)