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
set duration on scheduling
ulfertse708dcec940c
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rbindex f35d56ce25b..dcdf264f5aa 100644--- a/app/services/work_packages/set_schedule_service.rb+++ b/app/services/work_packages/set_schedule_service.rb@@ -86,16 +86,6 @@ class WorkPackages::SetScheduleServicealteredend- def date_rescheduling_delta(predecessor)- if predecessor.due_date.present?- predecessor.due_date - (predecessor.due_date_was || predecessor.due_date)- elsif predecessor.start_date.present?- predecessor.start_date - (predecessor.start_date_was || predecessor.start_date)- else- 0- end- end-# Schedules work packages based on either# - their descendants if they are parents# - their predecessors (or predecessors of their ancestors) if they are leaves@@ -111,8 +101,7 @@ class WorkPackages::SetScheduleService# start_date receives the minimum of the dates (start_date and due_date) of the descendants# due_date receives the maximum of the dates (start_date and due_date) of the descendantsdef reschedule_ancestor(scheduled, dependency)- scheduled.start_date = dependency.start_date- scheduled.due_date = dependency.due_date+ set_dates(scheduled, dependency.start_date, dependency.due_date)end# Calculates the dates of a work package based on its follows relations. The follows relations of@@ -141,8 +130,9 @@ class WorkPackages::SetScheduleServicedef reschedule_to_date(scheduled, date)new_start_date = [scheduled.start_date, date].compact.max- scheduled.due_date = new_start_date + scheduled.duration - 1 if scheduled.due_date- scheduled.start_date = new_start_date+ set_dates(scheduled,+ new_start_date,+ scheduled.due_date && (new_start_date + scheduled.duration - 1))enddef reschedule_by_delta(scheduled, delta, min_start_date)@@ -155,8 +145,9 @@ class WorkPackages::SetScheduleService# If the start_date of scheduled is nil at this point something# went wrong before. So we fix it now by setting the date.def schedule_on_missing_dates(scheduled, min_start_date)- scheduled.start_date = min_start_date- scheduled.due_date = scheduled.start_date if scheduled.due_date && scheduled.due_date < scheduled.start_date+ set_dates(scheduled,+ min_start_date,+ scheduled.due_date && scheduled.due_date < min_start_date ? min_start_date : scheduled.due_date)enddef follows_delta(dependency)@@ -166,4 +157,25 @@ class WorkPackages::SetScheduleService0endend++ def date_rescheduling_delta(predecessor)+ if predecessor.due_date.present?+ predecessor.due_date - (predecessor.due_date_was || predecessor.due_date)+ elsif predecessor.start_date.present?+ predecessor.start_date - (predecessor.start_date_was || predecessor.start_date)+ else+ 0+ end+ end++ def set_dates(work_package, start_date, due_date)+ work_package.start_date = start_date+ work_package.due_date = due_date+ work_package.duration = if start_date && due_date+ due_date - start_date + 1+ else+ # This needs to change to nil once duration can be set+ 1+ end+ endenddiff --git a/spec/factories/work_package_factory.rb b/spec/factories/work_package_factory.rbindex 93ca8e008bd..3199f9ea8d0 100644--- a/spec/factories/work_package_factory.rb+++ b/spec/factories/work_package_factory.rb@@ -44,6 +44,7 @@ FactoryBot.define doif start_date && due_datedue_date - start_date + 1else+ # This needs to change to nil once duration can be set1endenddiff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rbindex 21c5d1d6c5d..6b3de9b1dab 100644--- a/spec/services/work_packages/set_schedule_service_spec.rb+++ b/spec/services/work_packages/set_schedule_service_spec.rb@@ -142,6 +142,16 @@ describe WorkPackages::SetScheduleService do.to eql start_dateexpect(result.due_date).to eql due_date++ duration = if start_date && due_date+ (due_date - start_date + 1).to_i+ else+ # This needs to change to nil once duration can be set+ 1+ end++ expect(result.duration)+ .to eql durationendend