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

[#64628] Clearing the start date of a following phase is not possible

Dombi Attila7c8775533e87
diff --git a/app/forms/projects/life_cycles/form.rb b/app/forms/projects/life_cycles/form.rb
index e77f48c4b4c..69ec67bd2a1 100644
--- a/app/forms/projects/life_cycles/form.rb
+++ b/app/forms/projects/life_cycles/form.rb
@@ -118,14 +118,14 @@ module Projects::LifeCycles
def value(field_name)
case field_name
when :start_date
- model.start_date || model.default_start_date || model.start_date_before_type_cast
+ model.start_date || model.start_date_before_type_cast
when :finish_date
model.finish_date_before_type_cast
end
end
def start_date_disabled?
- model.follows_previous_phase? && model.default_start_date.present?
+ model.follows_previous_phase? && model.start_date.present?
end
def start_date_caption
diff --git a/app/services/project_phases/set_attributes_service.rb b/app/services/project_phases/set_attributes_service.rb
index 59d263b8a7d..bd50bab6bbc 100644
--- a/app/services/project_phases/set_attributes_service.rb
+++ b/app/services/project_phases/set_attributes_service.rb
@@ -36,8 +36,11 @@ module ProjectPhases
private
- def ensure_default_attributes(_params)
- model.start_date ||= model.default_start_date if model.default_start_date.present?
+ def ensure_default_attributes(params)
+ # Set default start date only when there is no user provided value.
+ if params[:start_date].nil? && model.default_start_date.present?
+ model.start_date ||= model.default_start_date
+ end
end
def set_calculated_duration
diff --git a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
index 2ef95c6ab14..31d676359cc 100644
--- a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
+++ b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
@@ -276,7 +276,13 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
dialog.close
- # Opening the Planning phase with no dates
+ # Save the Initiating phase to trigger rescheduling on the cleared Planning phase
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
+
+ dialog.submit # Saving the dialog is successful
+ dialog.expect_closed
+
+ # Opening the Planning phase with the default start date
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning, wait_angular: true)
# The start date automatically succeeds the life_cycle_initiating
@@ -313,6 +319,42 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
overview_page.within_life_cycle_container(life_cycle_planning) do
expect(page).to have_text formatted_date_range(life_cycle_planning)
end
+
+ # Make the Initiating phase incomplete to allow editing the Planning start date
+ life_cycle_initiating.update!(start_date: nil)
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning, wait_angular: true)
+
+ # Clear the start date of life_cycle_planning
+ dialog.clear_dates(fields: :start_date)
+
+ dialog.submit # Saving the dialog is successful
+ dialog.expect_closed
+
+ # Sidebar shows the refreshed life_cycle_planning
+ life_cycle_planning.reload
+ overview_page.within_life_cycle_container(life_cycle_planning) do
+ expect(page).to have_text formatted_date_range(life_cycle_planning)
+ end
+
+ # Planning start date is cleared in the database
+ expect(life_cycle_planning).to have_attributes(start_date: nil)
+
+ # Saving the Initiating phase will trigger rescheduling and assigns a start date for Planning
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
+
+ dialog.submit # Saving the dialog is successful
+ dialog.expect_closed
+
+ # Sidebar shows the refreshed life_cycle_planning
+ life_cycle_planning.reload
+ overview_page.within_life_cycle_container(life_cycle_planning) do
+ expect(page).to have_text formatted_date_range(life_cycle_planning)
+ end
+
+ # Planning start date is saved in the database
+ # Since the Initiating phase is now incomplete without a duration, the planning
+ # starts at the same date as the initiating.
+ expect(life_cycle_planning.start_date).to eq(initiating_finish_date)
end
end
diff --git a/spec/services/project_phases/set_attributes_service_spec.rb b/spec/services/project_phases/set_attributes_service_spec.rb
index 7ab27f1c962..7a5bea3ae02 100644
--- a/spec/services/project_phases/set_attributes_service_spec.rb
+++ b/spec/services/project_phases/set_attributes_service_spec.rb
@@ -108,7 +108,7 @@ RSpec.describe ProjectPhases::SetAttributesService, type: :model do
allow(phase).to receive(:default_start_date).and_return(date)
end
- context "and the previous_date is not set" do
+ context "and the previous start date is not set" do
let(:previous_date) { nil }
it "sets the model's start_date to the default_start_date" do
@@ -116,12 +116,20 @@ RSpec.describe ProjectPhases::SetAttributesService, type: :model do
end
end
- context "and the previous_date is set" do
+ context "and the previous start date is set" do
let(:previous_date) { Time.zone.yesterday }
it "does not sets the model's start_date to the default_start_date" do
expect { subject }.not_to change(phase, :start_date)
end
+
+ context "and the current start date is cleared" do
+ let(:call_attributes) { { start_date: "", finish_date: date + 27 } }
+
+ it "sets the model's start_date to nil" do
+ expect { subject }.to change(phase, :start_date).from(previous_date).to(nil)
+ end
+ end
end
end
diff --git a/spec/support/components/projects/project_life_cycles/edit_dialog.rb b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
index 0bd8c613ce4..046b4fcc244 100644
--- a/spec/support/components/projects/project_life_cycles/edit_dialog.rb
+++ b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
@@ -51,13 +51,15 @@ module Components
close if close_after_yield
end
- def clear_dates
- if has_button?("start_date_clear_button")
+ def clear_dates(fields: %i(start_date finish_date))
+ fields = Array(fields)
+
+ if fields.include?(:start_date) && has_button?("start_date_clear_button")
click_button("start_date_clear_button")
wait_for_form_preview_to_reload
end
- if has_button?("finish_date_clear_button")
+ if fields.include?(:finish_date) && has_button?("finish_date_clear_button")
click_button("finish_date_clear_button")
wait_for_form_preview_to_reload
end