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
[62641] Keep dates and update duration when toggling "Working days only"
Christophe Bliard2d4770253426
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex ff145431eba..b5971262e7e 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -92,12 +92,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributes# If +ignore_non_working_days+ has been changed, try deriving +due_date+ and# +start_date+ before +duration+.def derivable_date_attribute_by_others_presence- fields =- if work_package.ignore_non_working_days_changed?- %i[due_date start_date duration]- else- %i[duration due_date start_date]- end+ fields = %i[duration due_date start_date]fields.find { |field| derivable_by_others_presence?(field) }enddiff --git a/spec/features/work_packages/datepicker/datepicker_editable_finish_date_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_editable_finish_date_logic_spec.rbindex 47c0acd7b49..9a1a6fbb4e5 100644--- a/spec/features/work_packages/datepicker/datepicker_editable_finish_date_logic_spec.rb+++ b/spec/features/work_packages/datepicker/datepicker_editable_finish_date_logic_spec.rb@@ -381,7 +381,6 @@ RSpec.describe "Datepicker: Finish date field in auto-scheduled mode logic testdescribe "and change finish and non-working days, switching back to automatic (scenario 14b)" doit "preserves the finish date" do- pending "Enable when #62641 has been fixed"datepicker.set_date "2025-04-25"datepicker.expect_working_days_only(true)diff --git a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_logic_spec.rbindex 20d1c3b6921..c7bebb0eb5a 100644--- a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb+++ b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb@@ -522,46 +522,47 @@ RSpec.describe "Datepicker modal logic test cases (WP #43539)", :js, with_settindescribe "when all values set, changing include NWD to true (Scenario 15)" dolet(:current_attributes) do{- start_date: Date.parse("2021-02-11"),- due_date: Date.parse("2021-02-16"),- duration: 4+ start_date: Date.parse("2025-01-09"),+ due_date: Date.parse("2025-01-14"),+ duration: 4,+ ignore_non_working_days: false}end- it "conserves the duration and updates the finish date" do- datepicker.expect_start_date "2021-02-11"- datepicker.expect_due_date "2021-02-16"+ it "conserves the finish date and updates the duration" do+ datepicker.expect_start_date "2025-01-09"+ datepicker.expect_due_date "2025-01-14"datepicker.expect_duration 4datepicker.toggle_working_days_only- datepicker.expect_start_date "2021-02-11"- datepicker.expect_due_date "2021-02-14"- datepicker.expect_duration 4+ datepicker.expect_start_date "2025-01-09"+ datepicker.expect_due_date "2025-01-14"+ datepicker.expect_duration 6endenddescribe "when all values set and include NWD true, changing include NWD to false (Scenario 16)" dolet(:current_attributes) do{- start_date: Date.parse("2021-02-11"),- due_date: Date.parse("2021-02-14"),- duration: 4,+ start_date: Date.parse("2025-01-09"),+ due_date: Date.parse("2025-01-14"),+ duration: 6,ignore_non_working_days: true}end- it "conserves the duration and updates the finish date" do- datepicker.expect_start_date "2021-02-11"- datepicker.expect_due_date "2021-02-14"- datepicker.expect_duration 4+ it "conserves the finish date and updates the duration" do+ datepicker.expect_start_date "2025-01-09"+ datepicker.expect_due_date "2025-01-14"+ datepicker.expect_duration 6datepicker.expect_working_days_only falsedatepicker.toggle_working_days_onlydatepicker.expect_working_days_only true- datepicker.expect_start_date "2021-02-11"- datepicker.expect_due_date "2021-02-16"+ datepicker.expect_start_date "2025-01-09"+ datepicker.expect_due_date "2025-01-14"datepicker.expect_duration 4endend@@ -569,54 +570,54 @@ RSpec.describe "Datepicker modal logic test cases (WP #43539)", :js, with_settindescribe "when all values set and include NWD true, changing include NWD to false (Scenario 17)" dolet(:current_attributes) do{- start_date: Date.parse("2021-02-13"),- due_date: Date.parse("2021-02-14"),+ start_date: Date.parse("2025-01-11"),+ due_date: Date.parse("2025-01-12"),duration: 2,ignore_non_working_days: true}end- it "shifts the start date to soonest working day, and updates finish date to conserve duration" do- datepicker.expect_start_date "2021-02-13"- datepicker.expect_due_date "2021-02-14"+ it "shifts the start and finish dates to soonest working day, and updates duration accordingly" do+ datepicker.expect_start_date "2025-01-11"+ datepicker.expect_due_date "2025-01-12"datepicker.expect_duration 2datepicker.expect_working_days_only falsedatepicker.toggle_working_days_onlydatepicker.expect_working_days_only true- datepicker.expect_start_date "2021-02-15"- datepicker.expect_due_date "2021-02-16"- datepicker.expect_duration 2+ datepicker.expect_start_date "2025-01-13"+ datepicker.expect_due_date "2025-01-13"+ datepicker.expect_duration 1endenddescribe "when all values set and include NWD true, changing include NWD to false (Scenario 18)" dolet(:current_attributes) do{- start_date: Date.parse("2021-02-13"),- due_date: Date.parse("2021-02-23"),+ start_date: Date.parse("2025-01-11"),+ due_date: Date.parse("2025-01-21"),duration: 11,ignore_non_working_days: true}end- it "shifts the start date to soonest working day, and updates finish date to conserve duration" do- datepicker.expect_start_date "2021-02-13"- datepicker.expect_due_date "2021-02-23"+ it "shifts the start date to soonest working day, conserves the finish date, and updates duration accordingly" do+ datepicker.expect_start_date "2025-01-11"+ datepicker.expect_due_date "2025-01-21"datepicker.expect_duration 11datepicker.expect_working_days_only falsedatepicker.toggle_working_days_onlydatepicker.expect_working_days_only true- datepicker.expect_start_date "2021-02-15"- datepicker.expect_due_date "2021-03-01"- datepicker.expect_duration 11+ datepicker.expect_start_date "2025-01-13"+ datepicker.expect_due_date "2025-01-21"+ datepicker.expect_duration 7- apply_and_expect_saved duration: 11,- start_date: Date.parse("2021-02-15"),- due_date: Date.parse("2021-03-01"),+ apply_and_expect_saved duration: 7,+ start_date: Date.parse("2025-01-13"),+ due_date: Date.parse("2025-01-21"),ignore_non_working_days: falseendenddiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 4d234b34e7d..def7666656d 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -1339,12 +1339,12 @@ RSpec.describe WorkPackages::SetAttributesService,let(:call_attributes) { { ignore_non_working_days: true } }it_behaves_like "service call" do- it "updates the due date from start date and duration to include the non-working days" do- # start_date and duration are checked too to ensure they did not change+ it "keeps the dates and updates duration to include the non-working days" do+ # start_date and due_date are checked too to ensure they did not changeexpect { subject }.to change { work_package.slice(:start_date, :due_date, :duration) }.from(start_date: monday, due_date: next_monday, duration: 6)- .to(start_date: monday, due_date: next_monday - 2.days, duration: 6)+ .to(start_date: monday, due_date: next_monday, duration: 8)endendend@@ -1356,12 +1356,12 @@ RSpec.describe WorkPackages::SetAttributesService,let(:call_attributes) { { ignore_non_working_days: false } }it_behaves_like "service call" do- it "updates the due date from start date and duration to skip the non-working days" do+ it "keeps the dates and updates duration to include the non-working days" do# start_date and duration are checked too to ensure they did not changeexpect { subject }.to change { work_package.slice(:start_date, :due_date, :duration) }.from(start_date: monday, due_date: next_monday, duration: 8)- .to(start_date: monday, due_date: next_monday + 2.days, duration: 8)+ .to(start_date: monday, due_date: next_monday, duration: 6)endendend@@ -1373,22 +1373,23 @@ RSpec.describe WorkPackages::SetAttributesService,let(:call_attributes) { { ignore_non_working_days: false } }it_behaves_like "service call" do- it "updates the start date to be on next working day, and due date to accommodate duration" do+ it "updates the start date to be on next working day, keeps due date, and updates duration accordingly" doexpect { 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)+ .to(start_date: monday, due_date: friday, duration: 5)endend- context "with a new work package" do+ context 'with a new work package when "ignore non-working days" is switched to false, ' \+ "start date is on a non-working day, and duration is explicitly set" dolet(:work_package) dobuild(:work_package, start_date: monday - 1.day, due_date: friday, ignore_non_working_days: true)endlet(: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+ it "updates the start date to be on next working day, and updates due date to accommodate duration" doexpect { subject }.to change { work_package.slice(:start_date, :due_date, :duration) }.from(start_date: monday - 1.day, due_date: friday, duration: 6)@@ -1430,18 +1431,18 @@ RSpec.describe WorkPackages::SetAttributesService,endend- context 'when "ignore non-working days" is changed AND "finish date" is set to another date' do+ context 'when "ignore non-working days" is changed to true AND "finish date" is set to another date' dolet(:work_package) do- build_stubbed(:work_package, start_date: monday, due_date: next_monday, ignore_non_working_days: true)+ build_stubbed(:work_package, start_date: monday, due_date: wednesday, ignore_non_working_days: true)end- let(:call_attributes) { { due_date: wednesday, ignore_non_working_days: false } }+ let(:call_attributes) { { due_date: next_monday, ignore_non_working_days: false } }it_behaves_like "service call" do- it "updates the start date from due date and duration to skip the non-working days" do+ it "keeps the dates and updates the duration to include the non-working days" doexpect { subject }.to change { work_package.slice(:start_date, :due_date, :duration) }- .from(start_date: monday, due_date: next_monday, duration: 8)- .to(start_date: wednesday - 9.days, due_date: wednesday, duration: 8)+ .from(start_date: monday, due_date: wednesday, duration: 3)+ .to(start_date: monday, due_date: next_monday, duration: 6)endendend@@ -1461,6 +1462,22 @@ RSpec.describe WorkPackages::SetAttributesService,endendend++ context 'when "ignore non-working days" is changed AND "finish date" and "duration" are changed' do+ let(:work_package) do+ build_stubbed(:work_package, start_date: monday, due_date: next_monday, ignore_non_working_days: true)+ end+ let(:call_attributes) { { due_date: next_tuesday, duration: 3, ignore_non_working_days: false } }++ it_behaves_like "service call" do+ it "updates the start date from due date and duration according to the ignore non-working days value" do+ expect { subject }+ .to change { work_package.slice(:start_date, :due_date, :duration) }+ .from(start_date: monday, due_date: next_monday, duration: 8)+ .to(start_date: friday, due_date: next_tuesday, duration: 3)+ end+ end+ endendend