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

Ensure the start date is a working day when rescheduling following phases with a start date only.

Dombi Attila7594a6df6008
diff --git a/app/services/project_phases/activation_service.rb b/app/services/project_phases/activation_service.rb
index 691ea1d607e..6aadad14ca4 100644
--- a/app/services/project_phases/activation_service.rb
+++ b/app/services/project_phases/activation_service.rb
@@ -91,7 +91,7 @@ module ProjectPhases
end
def initial_reschedule_date(phase)
- phase.active? ? Day.next_working(from: phase.finish_date).date : phase.start_date
+ phase.active? ? phase.finish_date + 1 : phase.start_date
end
def default_contract_class
diff --git a/app/services/project_phases/reschedule_service.rb b/app/services/project_phases/reschedule_service.rb
index 678bc03d2a9..e51f8bc7069 100644
--- a/app/services/project_phases/reschedule_service.rb
+++ b/app/services/project_phases/reschedule_service.rb
@@ -50,15 +50,15 @@ module ProjectPhases
next unless phase.active?
if phase.date_range_set?
- next_start_date = set_phase_dates_and_next_start(phase, from)
+ next_start_date = reschedule_phase_and_retrieve_next_start(phase, from)
from = next_start_date unless next_start_date.nil?
elsif phase.start_date.present?
- phase.update(start_date: from)
+ reschedule_phase_start_only(phase, from)
end
end
end
- def set_phase_dates_and_next_start(phase, from)
+ def reschedule_phase_and_retrieve_next_start(phase, from)
return unless phase.duration&.positive?
date_range = calculate_date_range(from, duration: phase.duration)
@@ -74,6 +74,11 @@ module ProjectPhases
[days.first.date, days.last.date] if days.length == duration
end
+ def reschedule_phase_start_only(phase, from)
+ start_date = working_days_from(from, count: 1).first.date
+ phase.update(start_date: start_date)
+ end
+
def working_days_from(from, count:)
days = Day.working.from_range(from:, to: from.next_year).first(count)
if days.length < count && !days.empty?
diff --git a/app/services/project_phases/update_service.rb b/app/services/project_phases/update_service.rb
index a62bf1b3a83..ad9a4bfd9c0 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? ? Day.next_working(from: model.finish_date).date : model.start_date
+ model.active? ? model.finish_date + 1 : model.start_date
end
end
end
diff --git a/spec/services/project_phases/reschedule_service_spec.rb b/spec/services/project_phases/reschedule_service_spec.rb
index 70f983cfeb9..9878c242ca3 100644
--- a/spec/services/project_phases/reschedule_service_spec.rb
+++ b/spec/services/project_phases/reschedule_service_spec.rb
@@ -146,6 +146,7 @@ RSpec.describe ProjectPhases::RescheduleService, type: :model do
[
create(:project_phase, project:, start_date: nil, finish_date: date, duration: 5),
create(:project_phase, project:, start_date: date, finish_date: nil, duration: 5),
+ create(:project_phase, project:, start_date: date + 1, finish_date: nil, duration: 5),
create(:project_phase, project:, start_date: nil, finish_date: nil, duration: 5),
create(:project_phase, project:, start_date: date, finish_date: date, duration: 10)
]
@@ -156,8 +157,9 @@ RSpec.describe ProjectPhases::RescheduleService, type: :model do
expect(phases[0]).to have_attributes(start_date: nil, finish_date: date, 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)
+ expect(phases[2]).to have_attributes(start_date: from, finish_date: nil, duration: 5)
+ expect(phases[3]).to have_attributes(start_date: nil, finish_date: nil, duration: 5)
+ expect(phases[4]).to have_attributes(start_date: from, finish_date: from + 13, duration: 10)
end
end