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

[#64292] Disabling an incomplete phase leads to inconsistencies

Dombi Attilab99695ab74c2
diff --git a/app/services/project_phases/activation_service.rb b/app/services/project_phases/activation_service.rb
index 6af06964b56..b0da97a277f 100644
--- a/app/services/project_phases/activation_service.rb
+++ b/app/services/project_phases/activation_service.rb
@@ -74,13 +74,7 @@ module ProjectPhases
return unless first_definition
phase = project.phases.find_by(definition_id: first_definition.id)
- return unless phase.date_range_set?
-
- if phase.active?
- preceding_active_phase(phase) || phase
- else
- phase
- end
+ preceding_active_phase(phase) || phase
end
def preceding_active_phase(phase)
diff --git a/app/services/project_phases/update_service.rb b/app/services/project_phases/update_service.rb
index 99357f683dc..f9768126560 100644
--- a/app/services/project_phases/update_service.rb
+++ b/app/services/project_phases/update_service.rb
@@ -48,7 +48,7 @@ module ProjectPhases
end
def initial_reschedule_date
- model.active? ? model.finish_date + 1 : model.start_date
+ model.active? ? Day.next_working(from: model.finish_date).date : model.start_date
end
def following_phases
diff --git a/spec/features/projects/life_cycle/active_in_project_spec.rb b/spec/features/projects/life_cycle/active_in_project_spec.rb
index 25d94d83cd8..86eb1c5afa5 100644
--- a/spec/features/projects/life_cycle/active_in_project_spec.rb
+++ b/spec/features/projects/life_cycle/active_in_project_spec.rb
@@ -37,6 +37,7 @@ RSpec.describe "Projects life cycle settings", :js, with_flag: { stages_and_gate
create(:user,
member_with_permissions: {
project => %w[
+ edit_project_phases
select_project_phases
]
})
diff --git a/spec/services/project_phases/activation_service_spec.rb b/spec/services/project_phases/activation_service_spec.rb
index a5de20d2cf2..a7158361076 100644
--- a/spec/services/project_phases/activation_service_spec.rb
+++ b/spec/services/project_phases/activation_service_spec.rb
@@ -188,12 +188,12 @@ RSpec.describe ProjectPhases::ActivationService, type: :model do
context "without date range" do
let!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: nil, finish_date: nil) }
- it "doesn't reschedule" do
+ it "reschedules following phases using dates of the closest preceding phase with date range" do
service.call(active: true)
expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: date - 1)
expect(phase1.reload).to have_attributes(active: true, start_date: nil, finish_date: nil)
- expect(phase2.reload).to have_attributes(active: true, start_date: date + 7, finish_date: date + 9)
+ expect(phase2.reload).to have_attributes(active: true, start_date: date, finish_date: date + 2)
end
end
end
@@ -399,36 +399,36 @@ RSpec.describe ProjectPhases::ActivationService, type: :model do
context "with date range" do
let!(:phase1) { create_phase(definition: definitions[1], active: true, start_date: date + 2, finish_date: date + 3) }
- it "reschedules following phases using dates of that phase" do
+ it "reschedules following phases using dates of the closest preceding phase with date range" do
service.call(active: false)
expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: date - 1)
expect(phase1.reload).to have_attributes(active: false, start_date: date + 2, finish_date: date + 3)
- expect(phase2.reload).to have_attributes(active: true, start_date: date + 2, finish_date: date + 4)
+ expect(phase2.reload).to have_attributes(active: true, start_date: date, finish_date: date + 2)
end
end
context "when already deactivated" do
let!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: date + 2, finish_date: date + 3) }
- it "reschedules following phases using dates of that phase" do
+ it "reschedules following phases using dates of the closest preceding phase with date range" do
service.call(active: false)
expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: date - 1)
expect(phase1.reload).to have_attributes(active: false, start_date: date + 2, finish_date: date + 3)
- expect(phase2.reload).to have_attributes(active: true, start_date: date + 2, finish_date: date + 4)
+ expect(phase2.reload).to have_attributes(active: true, start_date: date, finish_date: date + 2)
end
end
context "without date range" do
let!(:phase1) { create_phase(definition: definitions[1], active: true, start_date: nil, finish_date: nil) }
- it "doesn't reschedule" do
+ it "reschedules following phases using dates of the closest preceding phase with date range" do
service.call(active: false)
expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: date - 1)
expect(phase1.reload).to have_attributes(active: false, start_date: nil, finish_date: nil)
- expect(phase2.reload).to have_attributes(active: true, start_date: date + 7, finish_date: date + 9)
+ expect(phase2.reload).to have_attributes(active: true, start_date: date, finish_date: date + 2)
end
end
end
diff --git a/spec/services/project_phases/update_service_spec.rb b/spec/services/project_phases/update_service_spec.rb
index 949440932fe..bc2df80e644 100644
--- a/spec/services/project_phases/update_service_spec.rb
+++ b/spec/services/project_phases/update_service_spec.rb
@@ -165,6 +165,17 @@ RSpec.describe ProjectPhases::UpdateService, type: :model do
end
end
+ context "for following phase with a start date only" do
+ let!(:phase) { create(:project_phase, project:, start_date: date, finish_date: date) }
+ let!(:following) { create(:project_phase, project:, start_date: date + 1, finish_date: nil, duration: 3) }
+
+ it "reschedules by moving the start date only" do
+ expect(service.call(start_date: date, finish_date: date + 1)).to be_success
+
+ expect(following).to have_attributes(start_date: date + 2, finish_date: nil, duration: 3)
+ end
+ end
+
context "for following phase with date range in the past" do
let!(:phase) { create(:project_phase, project:, start_date: date, finish_date: date) }
let!(:following) { create(:project_phase, project:, start_date: date - 10, finish_date: date - 10, duration: 3) }