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

Move scheduling changes to the RescheduleService

Dombi Attila0fbe82fb2fa1
diff --git a/app/services/project_phases/reschedule_service.rb b/app/services/project_phases/reschedule_service.rb
index 17c23df3bd8..3dde13ce29e 100644
--- a/app/services/project_phases/reschedule_service.rb
+++ b/app/services/project_phases/reschedule_service.rb
@@ -48,15 +48,19 @@ module ProjectPhases
def reschedule_phases(phases:, from:)
phases.each do |phase|
next unless phase.active?
- next unless phase.date_range_set?
- next unless phase.duration&.positive? # not updated using service that sets duration
- date_range = calculate_date_range(from, duration: phase.duration)
- next unless date_range
+ if phase.date_range_set?
+ next unless phase.duration&.positive? # not updated using service that sets duration
- next unless phase.update(start_date: date_range[0], finish_date: date_range[1])
+ date_range = calculate_date_range(from, duration: phase.duration)
+ next unless date_range
- from = date_range[1] + 1
+ next unless phase.update(start_date: date_range[0], finish_date: date_range[1])
+
+ from = date_range[1] + 1
+ elsif phase.start_date.present?
+ phase.update(start_date: from)
+ end
end
end
diff --git a/spec/services/project_phases/reschedule_service_spec.rb b/spec/services/project_phases/reschedule_service_spec.rb
index 3f308f048ca..70f983cfeb9 100644
--- a/spec/services/project_phases/reschedule_service_spec.rb
+++ b/spec/services/project_phases/reschedule_service_spec.rb
@@ -151,11 +151,11 @@ RSpec.describe ProjectPhases::RescheduleService, type: :model do
]
end
- it "skips them" do
+ it "reschedules only the ones with a start_date present" do
expect(service.call(phases:, from:)).to be_success
expect(phases[0]).to have_attributes(start_date: nil, finish_date: date, duration: 5)
- expect(phases[1]).to have_attributes(start_date: date, finish_date: nil, duration: 5)
+ expect(phases[1]).to have_attributes(start_date: from, finish_date: nil, duration: 5)
expect(phases[2]).to have_attributes(start_date: nil, finish_date: nil, duration: 5)
expect(phases[3]).to have_attributes(start_date: from, finish_date: from + 13, duration: 10)
end