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
Refactor reschedule service
Dombi Attila7113c80abd2a
diff --git a/app/services/project_phases/reschedule_service.rb b/app/services/project_phases/reschedule_service.rbindex d60aaa8bc6a..fb9cff4e48a 100644--- a/app/services/project_phases/reschedule_service.rb+++ b/app/services/project_phases/reschedule_service.rb@@ -49,17 +49,13 @@ module ProjectPhasesphases.each do |phase|next unless phase.active?- if phase.date_range_set?- next_start_date = reschedule_phase_and_retrieve_next_start(phase, from)- from = next_start_date unless next_start_date.nil?- else- reschedule_phase_start(phase, from)-- if phase.finish_date.present?- next_start_date = reschedule_phase_finish_and_retrieve_next_start(phase, from)- from = next_start_date unless next_start_date.nil?- end- end+ next_start_date = if phase.date_range_set?+ reschedule_phase_and_retrieve_next_start(phase, from)+ else+ reschedule_partial_phase_and_retrieve_next_start(phase, from)+ end++ from = next_start_date unless next_start_date.nil?endend@@ -79,6 +75,13 @@ module ProjectPhases[days.first.date, days.last.date] if days.length == durationend+ def reschedule_partial_phase_and_retrieve_next_start(phase, from)+ reschedule_phase_start(phase, from)+ return if phase.finish_date.blank?++ reschedule_phase_finish_and_retrieve_next_start(phase, from)+ end+def reschedule_phase_start(phase, from)start_date = working_days_from(from, count: 1).first.datephase.update(start_date:)diff --git a/spec/services/project_phases/activation_service_spec.rb b/spec/services/project_phases/activation_service_spec.rbindex c17a351b26d..876b52de10e 100644--- a/spec/services/project_phases/activation_service_spec.rb+++ b/spec/services/project_phases/activation_service_spec.rb@@ -215,7 +215,7 @@ RSpec.describe ProjectPhases::ActivationService, type: :model docontext "and later than the preceding phase finish date" dolet!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: nil, finish_date: date + 3) }- it "reschedules that and following phases filling the start date and maintining the finish date" do+ it "reschedules that and following phases filling the start date and maintaining the finish date" doservice.call(active: true)expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: date - 1)@@ -415,7 +415,7 @@ RSpec.describe ProjectPhases::ActivationService, type: :model docontext "and later than the preceding phase finish date" dolet!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: nil, finish_date: date + 3) }- it "reschedules that and following phases filling the start date and maintining the finish date" do+ it "reschedules that and following phases filling the start date and maintaining the finish date" doservice.call(active: true)expect(phase0.reload).to have_attributes(active: true, start_date: date - 1, finish_date: nil)@@ -498,7 +498,7 @@ RSpec.describe ProjectPhases::ActivationService, type: :model docontext "and later than the preceding phase finish date" dolet!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: nil, finish_date: date + 3) }- it "reschedules that and following phases filling the start date and maintining the finish date" do+ it "reschedules that and following phases filling the start date and maintaining the finish date" doservice.call(active: true)expect(phase0.reload).to have_attributes(active: true, start_date: nil, finish_date: date - 1)@@ -581,7 +581,7 @@ RSpec.describe ProjectPhases::ActivationService, type: :model docontext "and later than the following phase" dolet!(:phase1) { create_phase(definition: definitions[1], active: false, start_date: nil, finish_date: date + 10) }- it "reschedules that and following phases filling the start date and maintining the finish date" do+ it "reschedules that and following phases filling the start date and maintaining the finish date" doservice.call(active: true)expect(phase0.reload).to have_attributes(active: true, start_date: nil, finish_date: nil)