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

[#51173] Regression: most of the custom fields no longer appear in PDF for old projects (for new they do)

as-opa0ce0da867c8
diff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rb
index 412989d8deb..438b1e23396 100644
--- a/app/models/work_package/pdf_export/work_package_detail.rb
+++ b/app/models/work_package/pdf_export/work_package_detail.rb
@@ -141,7 +141,7 @@ module WorkPackage::PDFExport::WorkPackageDetail
cf = CustomField.find_by(id:)
return [] if cf.nil? || cf.formattable?
- return [] if work_package.project.work_package_custom_field_ids.exclude?(cf.id)
+ return [] unless cf.is_for_all? || work_package.project.work_package_custom_field_ids.include?(cf.id)
return [{ label: cf.name || form_key, name: form_key }]
end
diff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
index 63c53d7d538..edc441da6ad 100644
--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
@@ -32,16 +32,16 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do
include Redmine::I18n
include PDFExportSpecUtils
let(:type) do
- create(:type_bug, custom_fields: [long_text_custom_field, disabled_custom_field]).tap do |t|
- t.attribute_groups.first.attributes.push(disabled_custom_field.attribute_name, long_text_custom_field.attribute_name)
+ create(:type_bug, custom_fields: [cf_long_text, cf_disabled_in_project, cf_global_bool]).tap do |t|
+ t.attribute_groups.first.attributes.push(cf_disabled_in_project.attribute_name, cf_long_text.attribute_name)
end
end
let(:project) do
create(:project,
name: 'Foo Bla. Report No. 4/2021 with/for Case 42',
types: [type],
- work_package_custom_fields: [long_text_custom_field, disabled_custom_field],
- work_package_custom_field_ids: [long_text_custom_field.id]) # disabled_custom_field.id is disabled
+ work_package_custom_fields: [cf_long_text, cf_disabled_in_project, cf_global_bool],
+ work_package_custom_field_ids: [cf_long_text.id, cf_global_bool.id]) # cf_disabled_in_project.id is disabled
end
let(:user) do
create(:user,
@@ -52,11 +52,19 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do
let(:image_path) { Rails.root.join("spec/fixtures/files/image.png") }
let(:image_attachment) { Attachment.new author: user, file: File.open(image_path) }
let(:attachments) { [image_attachment] }
- let(:long_text_custom_field) { create(:issue_custom_field, :text, name: 'LongText') }
- let!(:disabled_custom_field) do
+ let(:cf_long_text) { create(:issue_custom_field, :text, name: 'LongText') }
+ let!(:cf_disabled_in_project) do
# NOT enabled by project.work_package_custom_field_ids => NOT in PDF
create(:float_wp_custom_field, name: 'DisabledCustomField')
end
+ let(:cf_global_bool) do
+ create(
+ :work_package_custom_field,
+ field_format: 'bool',
+ is_for_all: true,
+ default_value: true
+ )
+ end
let(:work_package) do
description = <<~DESCRIPTION
**Lorem** _ipsum_ ~~dolor~~ `sit` [amet](https://example.com/), consetetur sadipscing elitr.
@@ -79,8 +87,9 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do
story_points: 1,
description:,
custom_values: {
- long_text_custom_field.id => 'foo',
- disabled_custom_field.id => '6.25'
+ cf_long_text.id => 'foo',
+ cf_disabled_in_project.id => '6.25',
+ cf_global_bool.id => true
}).tap do |wp|
allow(wp)
.to receive(:attachments)