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

Keep current due date when changing "Working days only"

Christophe Bliard405ee097f098
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index aab4b85e677..fe4588b7b6a 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -416,14 +416,22 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributes
# this method is only called by #update_dates_from_self when there are no children
if work_package.due_date_came_from_user?
work_package.due_date
- elsif work_package.duration
- days.due_date(min_start, work_package.duration)
- elsif work_package.due_date
+ elsif reuse_current_due_date?
# if due date is before start date, then start is used as due date.
[min_start, work_package.due_date].max
+ elsif work_package.duration
+ days.due_date(min_start, work_package.duration)
end
end
+ def reuse_current_due_date?
+ return false if work_package.due_date.nil?
+ return true if work_package.ignore_non_working_days_came_from_user?
+
+ # use due date only if duration cannot be used
+ work_package.duration.nil?
+ end
+
def work_package
model
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
index 5baa293a8d8..29686e62a0e 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
@@ -461,11 +461,6 @@ export default class PreviewController extends DialogPreviewController {
return;
}
- if (!this.scheduleManuallyValue) {
- // Fix the start date to avoid that it gets changed accidentally
- this.markTouched('start_date');
- }
-
if (this.isBeingEdited('start_date')) {
this.untouchFieldsWhenStartDateIsEdited();
} else if (this.isBeingEdited('due_date')) {
diff --git a/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb
index f84f70eedfc..e39e0896fc9 100644
--- a/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb
+++ b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb
@@ -92,7 +92,7 @@ RSpec.describe "Datepicker logic on follow relationships", :js, with_settings: {
datepicker.expect_working_days_only false
datepicker.expect_start_date "2024-02-03", disabled: true
- datepicker.expect_due_date "2024-02-06"
+ datepicker.expect_due_date "2024-02-08" # did not change
datepicker.expect_disabled Date.parse("2024-02-01")
datepicker.expect_disabled Date.parse("2024-02-02") # predecessor's due date
datepicker.expect_not_disabled Date.parse("2024-02-03") # Saturday is non-working day but ignored
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index 83b99119f1c..781d27f7267 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -2002,7 +2002,7 @@ RSpec.describe WorkPackages::SetAttributesService,
let(:expected_attributes) do
{
start_date: next_monday,
- due_date: next_monday + 7.days
+ due_date: WorkPackages::Shared::WorkingDays.new.soonest_working_day(Time.zone.today + 5.days)
}
end
end
diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rb
index 19efb856ea4..126a49524dd 100644
--- a/spec/services/work_packages/update_service_integration_spec.rb
+++ b/spec/services/work_packages/update_service_integration_spec.rb
@@ -1317,13 +1317,13 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model do
let(:attributes) { { ignore_non_working_days: true } }
it "moves the start date earlier to start on a non-working day " \
- "and moves the due date too to keep same duration" do
+ "and keeps the current due date and updates the duration accordingly" do
expect(subject).to be_success
expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)
| subject | MTWTFSSmtwtfss | scheduling mode | days counting
| predecessor | XX | manual | working days only
- | work_package | XXX | automatic | all days
+ | work_package | XXXXX | automatic | all days
TABLE
end
end
@@ -1367,14 +1367,13 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model do
let(:attributes) { { ignore_non_working_days: false } }
- it "moves the start date earlier to start on a non-working day " \
- "and moves the due date too to keep same duration" do
+ it "moves the dates to the next working day and adjusts the duration accordingly" do
expect(subject).to be_success
expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)
- | subject | MTWTFSSmtwtfss | duration | scheduling mode | days counting
- | predecessor | XX | 2 | manual | working days only
- | work_package | XXXXX..XXX | 8 | automatic | working days only
+ | subject | MTWTFSSmtwtfss | duration | scheduling mode | days counting
+ | predecessor | XX | 2 | manual | working days only
+ | work_package | XXXXX..X | 6 | automatic | working days only
TABLE
end
end