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

fix(export): pdf uses Yes/No for boolean custom fields; XLS & CVS do not

as-op9b958f8ce3f9
diff --git a/app/models/exports/formatters/custom_field.rb b/app/models/exports/formatters/custom_field.rb
index 045b197bb9f..66dac9606b1 100644
--- a/app/models/exports/formatters/custom_field.rb
+++ b/app/models/exports/formatters/custom_field.rb
@@ -1,8 +1,8 @@
module Exports
module Formatters
class CustomField < Default
- def self.apply?(attribute, _export_format)
- attribute.start_with?("cf_")
+ def self.apply?(attribute, export_format)
+ export_format != :pdf && attribute.start_with?("cf_")
end
##
@@ -24,7 +24,7 @@ module Exports
case custom_field.field_format
when "bool"
value = object.typed_custom_value_for(custom_field)
- value ? I18n.t(:general_text_Yes) : I18n.t(:general_text_No)
+ value == nil ? false : value
when "text"
object.typed_custom_value_for(custom_field)
else
diff --git a/app/models/exports/formatters/custom_field_pdf.rb b/app/models/exports/formatters/custom_field_pdf.rb
new file mode 100644
index 00000000000..a299f785a16
--- /dev/null
+++ b/app/models/exports/formatters/custom_field_pdf.rb
@@ -0,0 +1,27 @@
+module Exports
+ module Formatters
+ class CustomFieldPdf < CustomField
+ def self.apply?(attribute, export_format)
+ export_format == :pdf && attribute.start_with?("cf_")
+ end
+
+ ##
+ # Print the value meant for export.
+ #
+ # - For boolean values, use the Yes/No formatting for the PDF
+ # treat nil as false
+ # - For long text values, output the plain value
+ def format_for_export(object, custom_field)
+ case custom_field.field_format
+ when "bool"
+ value = object.typed_custom_value_for(custom_field)
+ value ? I18n.t(:general_text_Yes) : I18n.t(:general_text_No)
+ when "text"
+ object.typed_custom_value_for(custom_field)
+ else
+ object.formatted_custom_value_for(custom_field)
+ end
+ end
+ end
+ end
+end
diff --git a/config/initializers/export_formats.rb b/config/initializers/export_formats.rb
index 26f2092b412..3b959de7863 100644
--- a/config/initializers/export_formats.rb
+++ b/config/initializers/export_formats.rb
@@ -15,6 +15,7 @@ Rails.application.configure do |application|
formatter WorkPackage, WorkPackage::Exports::Formatters::Costs
formatter WorkPackage, WorkPackage::Exports::Formatters::DoneRatio
formatter WorkPackage, Exports::Formatters::CustomField
+ formatter WorkPackage, Exports::Formatters::CustomFieldPdf
list Project, Projects::Exports::CSV
formatter Project, Exports::Formatters::CustomField