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

[61979] Switch successor to automatic mode even without rescheduling

Christophe Bliardd47295bafbbe
diff --git a/app/services/work_packages/schedule_dependency.rb b/app/services/work_packages/schedule_dependency.rb
index cded7b91ea8..47cd8f95747 100644
--- a/app/services/work_packages/schedule_dependency.rb
+++ b/app/services/work_packages/schedule_dependency.rb
@@ -192,8 +192,6 @@ class WorkPackages::ScheduleDependency
# rehydrate the predecessors and followers of follows relations
rehydrate_follows_relations
-
- fix_switching_to_automatic_mode_work_packages
end
# Returns all the descendants of moved and moving work packages that are not
@@ -235,13 +233,4 @@ class WorkPackages::ScheduleDependency
relation.to = work_package_by_id(relation.to_id)
end
end
-
- def fix_switching_to_automatic_mode_work_packages
- ids = switching_to_automatic_mode.map(&:id)
- known_work_packages.each do |work_package|
- if ids.include?(work_package.id)
- work_package.schedule_manually = false
- end
- end
- end
end
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rb
index 2349e27a310..a654be63dd7 100644
--- a/app/services/work_packages/set_schedule_service.rb
+++ b/app/services/work_packages/set_schedule_service.rb
@@ -84,6 +84,7 @@ class WorkPackages::SetScheduleService
WorkPackages::ScheduleDependency.new(moved_work_packages, switching_to_automatic_mode:)
.in_schedule_order do |scheduled, dependency|
changes_before = scheduled.changes
+ apply_switching_to_automatic_scheduling(scheduled)
reschedule(scheduled, dependency)
changes_after = scheduled.changes
@@ -93,6 +94,15 @@ class WorkPackages::SetScheduleService
altered
end
+ # Switches the scheduling mode of a work package to automatic if it is in the
+ # switching_to_automatic_mode array.
+ def apply_switching_to_automatic_scheduling(work_package)
+ switching_to_automatic_mode_ids = switching_to_automatic_mode.pluck(:id)
+ if switching_to_automatic_mode_ids.include?(work_package.id)
+ work_package.schedule_manually = false
+ end
+ end
+
# Schedules work packages based on either
# - their descendants if they are parents
# - their predecessors (or predecessors of their ancestors) if they are
diff --git a/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb b/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
index 55430a9424d..bf7ec47df10 100644
--- a/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
+++ b/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
@@ -134,7 +134,24 @@ RSpec.describe "Automatic scheduling logic test cases (WP #61054)", :js, with_se
describe "Scenario 26: Add a predecessor" do
context "when adding a predecessor to a work package" do
- it "changes the work package dates to start right after its predecessor", skip: "to be implemented later"
+ let_work_packages(<<~TABLE)
+ hierarchy | start date | due date | scheduling mode
+ future predecessor | | 2025-01-02 | manual
+ work package | 2025-01-08 | 2025-01-10 | manual
+ TABLE
+
+ it "changes the work package dates to start right after its predecessor" do
+ # add predecessor
+ work_packages_page.visit_tab!("relations")
+ work_packages_page.relations_tab.add_predecessor(future_predecessor)
+
+ # expect automatic with dates updated
+ open_date_picker
+ datepicker.expect_automatic_scheduling_mode
+ datepicker.expect_start_date "2025-01-03", disabled: true
+ datepicker.expect_due_date "2025-01-07", disabled: true
+ datepicker.expect_duration "3"
+ end
end
end
diff --git a/spec/services/relations/scheduling_mode_switching_spec.rb b/spec/services/relations/scheduling_mode_switching_spec.rb
index 403126484d8..b57f27193ce 100644
--- a/spec/services/relations/scheduling_mode_switching_spec.rb
+++ b/spec/services/relations/scheduling_mode_switching_spec.rb
@@ -93,6 +93,33 @@ RSpec.describe "Scheduling mode switching", # rubocop:disable RSpec/DescribeClas
end
end
+ context "with 2 manually scheduled work packages already having the correct dates" do
+ let_work_packages(<<~TABLE)
+ | subject | MTWTFSS | scheduling mode |
+ | pred | XX | manual |
+ | succ | XX | manual |
+ TABLE
+
+ before do
+ attributes = {
+ "relation_type" => "follows",
+ "from_id" => succ.id,
+ "to_id" => pred.id
+ }
+ Relations::CreateService.new(user:).call(attributes)
+ end
+
+ it "switches successor scheduling mode to automatic without rescheduling it" do
+ expect_work_packages_after_reload([pred, succ], <<~TABLE)
+ | subject | MTWTFSS | scheduling mode |
+ | pred | XX | manual |
+ | succ | XX | automatic |
+ TABLE
+ expect(pred.journals.count).to eq(1)
+ expect(succ.journals.count).to eq(2)
+ end
+ end
+
context "with a precedes relation with 2 manually scheduled work packages" do
let_work_packages(<<~TABLE)
| subject | MTWTFSS | scheduling mode |
diff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rb
index 265fda10ea3..6ba5dd1e9e7 100644
--- a/spec/services/work_packages/set_schedule_service_spec.rb
+++ b/spec/services/work_packages/set_schedule_service_spec.rb
@@ -41,8 +41,9 @@ RSpec.describe WorkPackages::SetScheduleService do
let(:work_package_start_date) { nil }
let(:initiating_work_package) { work_package }
let(:instance) do
- described_class.new(user:, work_package:, initiated_by: initiating_work_package)
+ described_class.new(user:, work_package:, initiated_by: initiating_work_package, switching_to_automatic_mode:)
end
+ let(:switching_to_automatic_mode) { [] }
let!(:following) { [] }
let(:follower1_start_date) { Time.zone.today + 1.day }
@@ -475,6 +476,25 @@ RSpec.describe WorkPackages::SetScheduleService do
end
end
end
+
+ context "when switching the successor to automatic mode without moving dates (adding relation)" do
+ let(:switching_to_automatic_mode) { [following_work_package1] }
+
+ before do
+ following_work_package1.update_column(:schedule_manually, true)
+ end
+
+ it "does not reschedule but switches the successor to automatic mode" do
+ expect(subject).to be_success
+
+ # returns the original and the successor which did not changed dates,
+ # but changed scheduling mode
+ expect(subject.all_results)
+ .to contain_exactly(work_package, following_work_package1)
+
+ expect(subject.all_results.last.schedule_manually).to be(false)
+ end
+ end
end
context "with only a parent scheduled automatically" do
diff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rb
index 98e91a6da92..3a5808ad501 100644
--- a/spec/support/components/work_packages/relations.rb
+++ b/spec/support/components/work_packages/relations.rb
@@ -168,6 +168,10 @@ module Components
expect(page).not_to have_test_selector("op-relation-row-#{actual_relatable.id}-delete-button")
end
+ def add_predecessor(work_package)
+ add_relation(type: :follows, relatable: work_package)
+ end
+
def add_relation(type:, relatable:, description: nil)
i18n_namespace = "#{WorkPackageRelationsTab::IndexComponent::I18N_NAMESPACE}.relations"
# Open create form