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

[#64836] Incorrect rescheduling after non working days are changed

Dombi Attila46ef0c505f7b
diff --git a/app/workers/projects/phases/apply_working_days_change_job.rb b/app/workers/projects/phases/apply_working_days_change_job.rb
index 92659930f76..86c2b4f29c4 100644
--- a/app/workers/projects/phases/apply_working_days_change_job.rb
+++ b/app/workers/projects/phases/apply_working_days_change_job.rb
@@ -33,15 +33,14 @@ class Projects::Phases::ApplyWorkingDaysChangeJob < ApplyWorkingDaysChangeJobBas
def apply_working_days_change
Project.where(id: applicable_phases.select(:project_id)).find_each do |project|
- phases = project.available_phases.to_a
- from = phases.filter_map(&:start_date).first
+ available_phases = project.available_phases.to_a
+ phase = available_phases.find(&:start_date?)
+ from = phase&.start_date
next unless from
- ProjectPhases::RescheduleService.new(user: User.current, project:).call(phases:, from:)
+ phases = available_phases.filter { it.position >= phase.position }
- project.journal_cause = journal_cause
-
- project.touch_and_save_journals
+ reschedule_project_phases(project:, phases:, from:)
end
end
@@ -53,4 +52,12 @@ class Projects::Phases::ApplyWorkingDaysChangeJob < ApplyWorkingDaysChangeJobBas
.active
.covering_dates_or_days_of_week(days_of_week:, dates:)
end
+
+ def reschedule_project_phases(project:, phases:, from:)
+ ProjectPhases::RescheduleService.new(user: User.current, project:).call(phases:, from:)
+
+ project.journal_cause = journal_cause
+
+ project.touch_and_save_journals
+ end
end
diff --git a/spec/workers/projects/phases/apply_working_days_change_job_spec.rb b/spec/workers/projects/phases/apply_working_days_change_job_spec.rb
index 076329f85d9..73cfa5ad34e 100644
--- a/spec/workers/projects/phases/apply_working_days_change_job_spec.rb
+++ b/spec/workers/projects/phases/apply_working_days_change_job_spec.rb
@@ -246,13 +246,13 @@ RSpec.describe Projects::Phases::ApplyWorkingDaysChangeJob do
allow(project).to receive(:touch_and_save_journals)
end
- it "calls RescheduleService with first start_date" do
+ it "calls RescheduleService with first start_date and only with phases after the start date" do
subject
expect(ProjectPhases::RescheduleService)
.to have_received(:new).with(user:, project:).once
expect(reschedule_service)
- .to have_received(:call).with(phases: phases, from: date + 1).once
+ .to have_received(:call).with(phases: phases[2..3], from: date + 1).once
end
it "journals project with correct cause" do