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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Ignore predecessors of manually scheduled parents
Christophe Bliardb739c997c4a2
diff --git a/app/services/work_packages/schedule_dependency.rb b/app/services/work_packages/schedule_dependency.rbindex 22d7cf6f6d9..cded7b91ea8 100644--- a/app/services/work_packages/schedule_dependency.rb+++ b/app/services/work_packages/schedule_dependency.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -80,13 +82,30 @@ class WorkPackages::ScheduleDependency@moving_work_packages_set.include?(work_package.id)end+ def parent_of(work_package)+ work_package_by_id(work_package.parent_id)+ end+def ancestors(work_package)@ancestors ||= {}@ancestors[work_package] ||= begin- parent = work_package_by_id(work_package.parent_id)+ parent = parent_of(work_package)if parent- [parent] + ancestors(parent)+ [parent, *ancestors(parent)]+ else+ []+ end+ end+ end++ def automatically_scheduled_ancestors(work_package)+ @automatically_scheduled_ancestors ||= {}+ @automatically_scheduled_ancestors[work_package] ||= begin+ parent = parent_of(work_package)++ if parent&.schedule_automatically?+ [parent, *automatically_scheduled_ancestors(parent)]else[]end@@ -120,9 +139,9 @@ class WorkPackages::ScheduleDependency:moved_work_packagesdef all_direct_and_indirect_follows_relations_for(work_package)- family = ancestors(work_package) + [work_package] + descendants(work_package)+ self_and_automatic_ancestors = [work_package] + automatically_scheduled_ancestors(work_package)follows_relations_by_follower_id- .fetch_values(*family.pluck(:id)) { [] }+ .fetch_values(*self_and_automatic_ancestors.pluck(:id)) { [] }.flatten.uniqenddiff --git a/spec/services/relations/create_service_integration_spec.rb b/spec/services/relations/create_service_integration_spec.rbindex 7b75c26dbfd..c52d8a8ec33 100644--- a/spec/services/relations/create_service_integration_spec.rb+++ b/spec/services/relations/create_service_integration_spec.rb@@ -73,8 +73,41 @@ RSpec.describe Relations::CreateService do| child_predecessor | X | manual| parent | XX..X | automatic| child | XX..X | automatic- # this will become the predecessor of the childTABLEendend++ context "when creating a successor relation between a predecessor and a parent being manually scheduled" do+ let_work_packages(<<~TABLE)+ | hierarchy | MTWTFSS | scheduling mode | predecessors+ | child_predecessor | X | manual |+ | parent | X..XX | manual |+ | child | XX | automatic | child_predecessor+ # this will become the predecessor of the parent+ | parent_predecessor | XXX | manual |+ TABLE+ let(:attributes) do+ {+ "relation_type" => "follows",+ "from_id" => parent.id,+ "to_id" => parent_predecessor.id+ }+ end++ it "does not impact dates of an automatically scheduled child, because the parent is manually scheduled" do+ expect(subject).to be_success+ relation = subject.result+ expect(relation.predecessor).to eq(parent_predecessor)+ expect(relation.successor).to eq(parent)++ expect_work_packages_after_reload([parent_predecessor, parent, child, child_predecessor], <<~TABLE)+ | subject | MTWTFSS | scheduling mode+ | child_predecessor | X | manual |+ | parent_predecessor | XXX | manual |+ | parent | X..XX | manual |+ | child | XX | automatic |+ TABLE+ expect(subject.all_results).to contain_exactly(relation)+ end+ endenddiff --git a/spec/services/work_packages/schedule_dependency/dependency_spec.rb b/spec/services/work_packages/schedule_dependency/dependency_spec.rbindex 25f6b394d1f..4a80b179100 100644--- a/spec/services/work_packages/schedule_dependency/dependency_spec.rb+++ b/spec/services/work_packages/schedule_dependency/dependency_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -167,16 +169,16 @@ RSpec.describe WorkPackages::ScheduleDependency::Dependency docontext "for dependency of the first follower parent" dolet(:work_package_used_in_dependency) { first_follower_parent }- it "returns an array with the work_package and the first follower ids" do- expect(subject.dependent_ids).to contain_exactly(work_package.id, first_follower.id)+ it "returns an array with the first follower id" do+ expect(subject.dependent_ids).to contain_exactly(first_follower.id)endendcontext "for dependency of the first follower grandparent" dolet(:work_package_used_in_dependency) { first_follower_grandparent }- it "returns an array with the work_package, the first follower, and the first follower parent ids" do- expect(subject.dependent_ids).to contain_exactly(work_package.id, first_follower.id, first_follower_parent.id)+ it "returns an array with the first follower and the first follower parent ids" do+ expect(subject.dependent_ids).to contain_exactly(first_follower.id, first_follower_parent.id)endend@@ -240,8 +242,8 @@ RSpec.describe WorkPackages::ScheduleDependency::Dependency docontext "for dependency of the follower parent" dolet(:work_package_used_in_dependency) { follower_parent }- it "returns an array with the work_package, the follower, and the follower child ids" do- expect(subject.dependent_ids).to contain_exactly(work_package.id, follower.id, follower_child.id)+ it "returns an array with the follower and the follower child ids" do+ expect(subject.dependent_ids).to contain_exactly(follower.id, follower_child.id)endendenddiff --git a/spec/services/work_packages/set_schedule_service_working_days_spec.rb b/spec/services/work_packages/set_schedule_service_working_days_spec.rbindex bba6a500b6c..1b69091c809 100644--- a/spec/services/work_packages/set_schedule_service_working_days_spec.rb+++ b/spec/services/work_packages/set_schedule_service_working_days_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -676,6 +678,32 @@ RSpec.describe WorkPackages::SetScheduleService, "working days" doendend+ context "with a predecessor and a child automatically scheduled" do+ let_work_packages(<<~TABLE)+ hierarchy | MTWTFSS | scheduling mode | predecessors+ predecessor | XX | manual |+ work_package | XX | automatic | predecessor+ child | XX | automatic |+ TABLE++ context "when switching to manual scheduling" do+ before do+ change_work_packages([work_package], <<~TABLE)+ subject | scheduling mode |+ work_package | manual |+ TABLE+ end++ it "switches the child to manual scheduling too" do+ expect_work_packages(subject.all_results, <<~TABLE)+ subject | scheduling mode |+ work_package | manual |+ child | manual |+ TABLE+ end+ end+ end+context "with a single successor having a parent" docontext "when moving forward" dolet_work_packages(<<~TABLE)