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

Shift dates to soonest working day for new work packages

Christophe Bliard981fc69c36f6
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index c801922094d..d29b08fab1d 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -56,6 +56,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
else
update_dates
end
+ shift_dates_to_soonest_working_days
update_duration
update_derivable
update_project_dependent_attributes
@@ -249,7 +250,6 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
def update_dates
unify_dates if work_package_now_milestone?
- shift_dates_to_soonest_working_days unless work_package.ignore_non_working_days?
min_start = new_start_date
@@ -265,6 +265,8 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
end
def shift_dates_to_soonest_working_days
+ return if work_package.ignore_non_working_days?
+
work_package.start_date = days.soonest_working_day(work_package.start_date)
work_package.due_date = days.soonest_working_day(work_package.due_date)
end
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index d832342b75c..c29cdd1dd25 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -1157,6 +1157,22 @@ describe WorkPackages::SetAttributesService,
.to(start_date: monday, due_date: next_monday, duration: 6)
end
end
+
+ context 'with a new work package' do
+ let(:work_package) do
+ build(:work_package, start_date: monday - 1.day, due_date: friday, ignore_non_working_days: true)
+ end
+ let(:call_attributes) { { ignore_non_working_days: false, duration: 6 } }
+
+ it_behaves_like 'service call' do
+ it "updates the start date to be on next working day, and due date to accommodate duration" do
+ expect { subject }
+ .to change { work_package.slice(:start_date, :due_date, :duration) }
+ .from(start_date: monday - 1.day, due_date: friday, duration: 6)
+ .to(start_date: monday, due_date: next_monday, duration: 6)
+ end
+ end
+ end
end
context 'when "ignore non-working days" is switched to false and "finish date" is on a non-working day' do