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

create field_format_calculated_value scope and use it

Ivan Kuchin4790725ba29a
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 2e4c6ba2230..8bbfadc8d86 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -52,6 +52,8 @@ class CustomField < ApplicationRecord
scope :hierarchy_root_and_children, -> { includes(hierarchy_root: { children: :children }) }
scope :required, -> { where(is_required: true) }
+ scope :field_format_calculated_value, -> { where(field_format: "calculated_value") }
+
acts_as_list scope: [:type]
validates :field_format, presence: true
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rb
index b754f0e7afa..63a6043ec22 100644
--- a/app/models/custom_field/calculated_value.rb
+++ b/app/models/custom_field/calculated_value.rb
@@ -50,7 +50,7 @@ module CustomField::CalculatedValue
def affected_calculated_fields(changed_cf_ids)
return [] if changed_cf_ids.empty?
- to_check = select(&:field_format_calculated_value?)
+ to_check = field_format_calculated_value
# include calculated value fields themselves
all_affected, to_check = to_check.partition { it.id.in?(changed_cf_ids) }
diff --git a/app/services/projects/concerns/set_calculated_custom_field_values.rb b/app/services/projects/concerns/set_calculated_custom_field_values.rb
index 91bc793902b..d65a77597aa 100644
--- a/app/services/projects/concerns/set_calculated_custom_field_values.rb
+++ b/app/services/projects/concerns/set_calculated_custom_field_values.rb
@@ -42,7 +42,7 @@ module Projects::Concerns
custom_field_value_params = params[:custom_field_values]
return params unless custom_field_value_params
- calculated_field_ids = model.all_available_custom_fields.select(&:field_format_calculated_value?).map(&:id)
+ calculated_field_ids = model.all_available_custom_fields.field_format_calculated_value.pluck(:id)
custom_field_value_params = custom_field_value_params.reject { |id, _| id.to_s.to_i.in?(calculated_field_ids) }
params.merge(custom_field_values: custom_field_value_params)