Skip to content

Commit a69cd9f

Browse files
committed
[#64524] Update all affected Calculated Values when score is updated
1 parent dd6e684 commit a69cd9f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/services/custom_fields/hierarchy/hierarchical_item_service.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,25 @@ def create_child_item(validation:, sort_order: nil)
178178

179179
def update_item_attributes(item:, attributes:)
180180
if item.update(label: attributes[:label], short: attributes[:short], score: attributes[:score])
181+
update_calculated_values_using_hierarchy(item.root)
181182
Success(item)
182183
else
183184
Failure(item.errors)
184185
end
185186
end
186187

188+
# Recalculates Calculated Values in all projects that use the hierarchy's custom field
189+
def update_calculated_values_using_hierarchy(hierarchy)
190+
custom_field = hierarchy.custom_field
191+
192+
custom_field.projects.each do |project|
193+
affected_cfs = project.available_custom_fields.affected_calculated_fields([custom_field.id])
194+
195+
project.calculate_custom_fields(affected_cfs)
196+
project.save if project.changed_for_autosave?
197+
end
198+
end
199+
187200
def update_item_order(item:, new_sort_order:)
188201
target_item = item.siblings.find_by(sort_order: new_sort_order)
189202
if target_item.present?

0 commit comments

Comments
 (0)