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

[62261] Fix error displayed when switching parent to automatic

Christophe Bliardc8f1454bb723
diff --git a/app/controllers/work_packages/date_picker_controller.rb b/app/controllers/work_packages/date_picker_controller.rb
index f91dc8f7728..7d37d70b53a 100644
--- a/app/controllers/work_packages/date_picker_controller.rb
+++ b/app/controllers/work_packages/date_picker_controller.rb
@@ -249,6 +249,9 @@ class WorkPackages::DatePickerController < ApplicationController
def set_date_attributes_to_work_package
wp_params = work_package_datepicker_params
+ if wp_params["schedule_manually"] == "false"
+ wp_params = wp_params.without("start_date", "due_date")
+ end
if wp_params.present?
WorkPackages::SetAttributesService
diff --git a/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb b/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
index 7ca55f1df9c..eccb9589c0e 100644
--- a/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
+++ b/spec/features/work_packages/scheduling/automatic_scheduling_logic_spec.rb
@@ -391,4 +391,75 @@ RSpec.describe "Automatic scheduling logic test cases (WP #61054)", :js, with_se
end
end
end
+
+ describe "Bug #62261: Invalid error displayed when switching parent to automatic" do
+ context "when changing dates to the ones that would be computed by automatic mode and then switching to automatic" do
+ let_work_packages(<<~TABLE)
+ hierarchy | start date | due date | scheduling mode
+ work package | 2025-01-27 | 2025-02-06 | manual
+ child | | | manual
+ TABLE
+
+ it "does not display a 'read-only' error" do
+ open_date_picker
+ datepicker.set_start_date("")
+ datepicker.set_due_date("")
+
+ datepicker.toggle_scheduling_mode
+
+ datepicker.expect_start_date "", disabled: true
+ datepicker.expect_due_date "", disabled: true
+ read_only_error = I18n.t("activerecord.errors.messages.error_readonly")
+ expect(datepicker.container).to have_no_text(/#{Regexp.escape(read_only_error)}/i)
+
+ apply_and_expect_saved(
+ start_date: nil,
+ due_date: nil,
+ duration: nil,
+ schedule_manually: false
+ )
+ end
+ end
+
+ context "when manually changing dates of an automatically scheduled successor, and then switch back to automatic" do
+ let_work_packages(<<~TABLE)
+ subject | start date | due date | scheduling mode | predecessors
+ predecessor | 2025-01-14 | 2025-01-16 | manual |
+ work package | 2025-01-17 | 2025-01-17 | automatic | predecessor
+ TABLE
+
+ it "does not display a 'must be set to a later date' error" do
+ open_date_picker
+ datepicker.toggle_scheduling_mode
+ datepicker.expect_manual_scheduling_mode
+
+ # change dates in manual mode
+ datepicker.set_start_date("2025-01-06")
+ datepicker.set_due_date("2025-01-08")
+
+ datepicker.expect_start_date "2025-01-06"
+ datepicker.expect_due_date "2025-01-08"
+ datepicker.expect_duration "3"
+
+ # switch back to automatic
+ datepicker.toggle_scheduling_mode
+ datepicker.expect_automatic_scheduling_mode
+
+ # dates should be derived from predecessors, and the duration is the
+ # initial one despite the manual change
+ datepicker.expect_start_date "2025-01-17", disabled: true
+ datepicker.expect_due_date "2025-01-17", disabled: true
+ datepicker.expect_duration "1"
+
+ expect(datepicker.container).to have_no_text(/Can only be set to ....-..-.. or later/i)
+
+ apply_and_expect_saved(
+ start_date: Date.parse("2025-01-17"),
+ due_date: Date.parse("2025-01-17"),
+ duration: 1,
+ schedule_manually: false
+ )
+ end
+ end
+ end
end