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 following_phases to the Phase model.

Dombi Attilad84cac6c9a56
diff --git a/app/models/project/phase.rb b/app/models/project/phase.rb
index 5951d65b7f2..fc6587b2511 100644
--- a/app/models/project/phase.rb
+++ b/app/models/project/phase.rb
@@ -85,10 +85,6 @@ class Project::Phase < ApplicationRecord
Day.working.from_range(from: start_date, to: finish_date).count
end
- def follows_previous_phase?
- !!previous_phase&.date_range_set?
- end
-
def default_start_date
return @default_start_date if defined?(@default_start_date)
@@ -96,14 +92,23 @@ class Project::Phase < ApplicationRecord
@default_start_date = previous_finish_date && Day.next_working(from: previous_finish_date).date
end
- private
+ def previous_phases
+ return @previous_phases if defined?(@previous_phases)
+
+ @previous_phases = project.available_phases.select { it.position < position }
+ end
def previous_phase
- return @previous_phase if defined?(@previous_phase)
+ previous_phases.last
+ end
+
+ def follows_previous_phase?
+ !!previous_phase&.date_range_set?
+ end
+
+ def following_phases
+ return @following_phases if defined?(@following_phases)
- @previous_phase = project
- .available_phases
- .select { it.position < position }
- .last
+ @following_phases = project.available_phases.select { it.position > position }
end
end
diff --git a/app/services/project_phases/update_service.rb b/app/services/project_phases/update_service.rb
index f9768126560..a62bf1b3a83 100644
--- a/app/services/project_phases/update_service.rb
+++ b/app/services/project_phases/update_service.rb
@@ -44,15 +44,11 @@ module ProjectPhases
def reschedule_following_phases
RescheduleService.new(user:, project:)
- .call(phases: following_phases, from: initial_reschedule_date)
+ .call(phases: model.following_phases, from: initial_reschedule_date)
end
def initial_reschedule_date
model.active? ? Day.next_working(from: model.finish_date).date : model.start_date
end
-
- def following_phases
- project.available_phases.select { it.position > model.position }
- end
end
end