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
update logic for activating one phase to also reschedule it when possible
Ivan Kuchin62a79f8f245f
diff --git a/app/services/project_life_cycle_steps/activation_service.rb b/app/services/project_life_cycle_steps/activation_service.rbindex c7f088000f0..81530d7727b 100644--- a/app/services/project_life_cycle_steps/activation_service.rb+++ b/app/services/project_life_cycle_steps/activation_service.rb@@ -47,8 +47,8 @@ module ProjectLifeCycleStepsupsert(active:)- if (first_phase = find_first_phase)- UpdateService.new(user:, model: first_phase).call+ if (phase = reschedule_from_phase)+ UpdateService.new(user:, model: phase).callelseproject.touch_and_save_journals@@ -69,11 +69,22 @@ module ProjectLifeCycleSteps)end- def find_first_phase- definition_id = definitions.min_by(&:position)&.id- return unless definition_id+ def reschedule_from_phase+ first_definition = definitions.min_by(&:position)+ return unless first_definition- project.phases.find_by(definition_id:)+ phase = project.phases.find_by(definition_id: first_definition.id)+ return unless phase.range_set?++ if phase.active?+ preceding_active_phase(phase) || phase+ else+ phase+ end+ end++ def preceding_active_phase(phase)+ project.available_phases.reverse.find { it.range_set? && it.position < phase.position }enddef default_contract_classdiff --git a/spec/services/project_life_cycle_steps/activation_service_spec.rb b/spec/services/project_life_cycle_steps/activation_service_spec.rbindex 2fdb0e0d7a0..42175fbf02a 100644--- a/spec/services/project_life_cycle_steps/activation_service_spec.rb+++ b/spec/services/project_life_cycle_steps/activation_service_spec.rb@@ -164,24 +164,24 @@ RSpec.describe ProjectLifeCycleSteps::ActivationService, type: :model docontext "with date range" dolet!(:phase1) { create_phase(definition: definitions[1], date_range: date + 2..date + 3, active: false) }- it "reschedules following phases" do+ it "reschedules that and following phases" doservice.call(active: true)expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)- expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: true)- expect(phase2.reload).to have_attributes(start_date: date + 4, finish_date: date + 6, active: true)+ expect(phase1.reload).to have_attributes(start_date: date, finish_date: date + 1, active: true)+ expect(phase2.reload).to have_attributes(start_date: date + 2, finish_date: date + 4, active: true)endendcontext "when already activated" dolet!(:phase1) { create_phase(definition: definitions[1], date_range: date + 2..date + 3, active: true) }- it "reschedules following phases" do+ it "reschedules that and following phases" doservice.call(active: true)expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)- expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: true)- expect(phase2.reload).to have_attributes(start_date: date + 4, finish_date: date + 6, active: true)+ expect(phase1.reload).to have_attributes(start_date: date, finish_date: date + 1, active: true)+ expect(phase2.reload).to have_attributes(start_date: date + 2, finish_date: date + 4, active: true)endend