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

UpdateAncestors patch to deal with derived_remaining_time

Marcello Rochaf8fd365b45f5
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/update_ancestors_service_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/update_ancestors_service_patch.rb
index aa164c43055..a8f8eb8effc 100644
--- a/modules/backlogs/lib/open_project/backlogs/patches/update_ancestors_service_patch.rb
+++ b/modules/backlogs/lib/open_project/backlogs/patches/update_ancestors_service_patch.rb
@@ -39,12 +39,13 @@ module OpenProject::Backlogs::Patches::UpdateAncestorsServicePatch
def inherit_attributes(ancestor, loader, attributes)
super
- inherit_remaining_hours(ancestor, loader) if inherit?(attributes, :remaining_hours)
+ derive_remaining_hours(ancestor, loader) if inherit?(attributes, :remaining_hours)
end
- def inherit_remaining_hours(ancestor, loader)
- ancestor.remaining_hours = all_remaining_hours(loader.leaves_of(ancestor)).sum.to_f
- ancestor.remaining_hours = nil if ancestor.remaining_hours == 0.0
+ def derive_remaining_hours(work_package, loader)
+ descendants = loader.descendants_of(work_package)
+
+ work_package.derived_remaining_hours = not_zero(all_remaining_hours(descendants).sum.to_f)
end
def all_remaining_hours(work_packages)