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
Keep duration when setting dates from soonest start date
Christophe Bliard844af0e0af9c
diff --git a/app/services/work_packages/schedule_dependency/dependency.rb b/app/services/work_packages/schedule_dependency/dependency.rbindex f392667286c..61554bff1a3 100644--- a/app/services/work_packages/schedule_dependency/dependency.rb+++ b/app/services/work_packages/schedule_dependency/dependency.rb@@ -52,9 +52,10 @@ class WorkPackages::ScheduleDependency::Dependencyenddef soonest_start_date- follows_relations- .filter_map(&:successor_soonest_start)- .max+ @soonest_start_date ||=+ follows_relations+ .filter_map(&:successor_soonest_start)+ .maxenddef start_datediff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rbindex e36e4ee20dc..7985fd41915 100644--- a/app/services/work_packages/set_schedule_service.rb+++ b/app/services/work_packages/set_schedule_service.rb@@ -126,6 +126,9 @@ class WorkPackages::SetScheduleService# Calculates the dates of a work package based on its follows relations.#+ # The start date of a work package is constrained by its direct and indirect+ # predecessors, as it must start strictly after all predecessors finish.+ ## The follows relations of ancestors are considered to be equal to own follows# relations as they inhibit moving a work package just the same. Only leaf# work packages are calculated like this.@@ -139,42 +142,36 @@ class WorkPackages::SetScheduleService# work package moved to an earlier date:# - following work packages do not move at all.def reschedule_by_predecessors(scheduled, dependency)- min_start_date = dependency.soonest_start_date- return unless min_start_date+ return unless dependency.soonest_start_date- if !scheduled.start_date- schedule_on_missing_dates(scheduled, min_start_date)- elsif min_start_date > scheduled.start_date- reschedule_to_date(scheduled, min_start_date)- end+ new_start_date = [scheduled.start_date, dependency.soonest_start_date].compact.max+ new_due_date = determine_due_date(scheduled, new_start_date)+ set_dates(scheduled, new_start_date, new_due_date)end- def reschedule_to_date(scheduled, date)- new_start_date = [scheduled.start_date, date].compact.max- # a new due date is set only if the moving work package already has one- if scheduled.due_date- new_due_date = [- WorkPackages::Shared::Days.for(scheduled).due_date(new_start_date, scheduled.duration),- new_start_date,- scheduled.due_date- ].compact.max- end+ def determine_due_date(work_package, start_date)+ # due date is set only if the moving work package already has one or has a+ # duration. If not, due date is nil (and duration will be nil too).+ return unless work_package.due_date || work_package.duration- set_dates(scheduled, new_start_date, new_due_date)- end+ due_date =+ if work_package.duration+ days(work_package).due_date(start_date, work_package.duration)+ else+ work_package.due_date+ end- def schedule_on_missing_dates(scheduled, min_start_date)- min_start_date = WorkPackages::Shared::Days.for(scheduled).soonest_working_day(min_start_date)- set_dates(scheduled,- min_start_date,- scheduled.due_date && scheduled.due_date < min_start_date ? min_start_date : scheduled.due_date)+ # if due date is before start date, then start is used as due date.+ [start_date, due_date].maxenddef set_dates(work_package, start_date, due_date)work_package.start_date = start_datework_package.due_date = due_date- work_package.duration = WorkPackages::Shared::Days- .for(work_package)- .duration(start_date, due_date)+ work_package.duration = days(work_package).duration(start_date, due_date)+ end++ def days(work_package)+ WorkPackages::Shared::Days.for(work_package)endenddiff --git a/spec/services/work_packages/set_schedule_service_working_days_spec.rb b/spec/services/work_packages/set_schedule_service_working_days_spec.rbindex d07b740e14d..90a949b0ad4 100644--- a/spec/services/work_packages/set_schedule_service_working_days_spec.rb+++ b/spec/services/work_packages/set_schedule_service_working_days_spec.rb@@ -593,6 +593,31 @@ describe WorkPackages::SetScheduleService, 'working days' doendendend++ context 'with successor having only duration' do+ context 'when setting dates on predecessor' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | |+ follower | | duration 3, follows work_package+ CHART++ before do+ change_schedule([work_package], <<~CHART)+ days | MTWTFSS |+ work_package | XX |+ CHART+ end++ it 'schedules successor to start after predecessor and keeps the duration (#44479)' do+ expect(subject.all_results).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX |+ follower | X..XX |+ CHART+ end+ end+ endendcontext 'with a parent' do