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
[63296] Fix date error when creating parent-child relationship
Christophe Bliard0d06aa2bae2f
diff --git a/app/models/work_package/scheduling_rules.rb b/app/models/work_package/scheduling_rules.rbindex 5aa8aa84abd..1b9994a08df 100644--- a/app/models/work_package/scheduling_rules.rb+++ b/app/models/work_package/scheduling_rules.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -58,7 +60,13 @@ module WorkPackage::SchedulingRules# C is 2017/07/28 (CP due date: 25, 26 and 27 is the 2 days lag => 28)## The soonest start for this work package is the maximum of these values: 2017/07/28.- def soonest_start+ #+ # @param working_days_from [WorkPackage, nil] the work package for which to+ # find the next working day after the soonest start given by the scheduling+ # relations. If nil, the work package itself is used. Useful for a work+ # package calculating the soonest start given by its parent as it may have a+ # different `ignore_working_days` value than its parent.+ def soonest_start(working_days_from: nil)@scheduling_relations_soonest_start ||=Relation.used_for_scheduling_of(self)@@ -69,7 +77,7 @@ module WorkPackage::SchedulingRules# The final result should not be cached as it depends on# ignore_non_working_days value, which can change between consecutive calls# to #soonest_start- WorkPackages::Shared::Days.for(self)- .soonest_working_day(@scheduling_relations_soonest_start)+ days = WorkPackages::Shared::Days.for(working_days_from || self)+ days.soonest_working_day(@scheduling_relations_soonest_start)endenddiff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex fe4588b7b6a..a2cabd2b3da 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -398,7 +398,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesdays.soonest_working_day(new_start_date_from_parent)else- min_start = new_start_date_from_parent || work_package.soonest_start+ min_start = [new_start_date_from_parent, work_package.soonest_start].compact.maxdays.soonest_working_day(min_start)endend@@ -409,7 +409,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesreturn unless work_package.parent_id_changed? &&work_package.parent- work_package.parent.soonest_start+ work_package.parent.soonest_start(working_days_from: work_package)enddef new_due_date(min_start)diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rbindex 126a49524dd..4ba40e7efae 100644--- a/spec/services/work_packages/update_service_integration_spec.rb+++ b/spec/services/work_packages/update_service_integration_spec.rb@@ -1056,6 +1056,102 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model doendend+ context "when the work package has its own predecessor which ends later than its future " \+ "parent predecessor (Bug #63296)" do+ let_work_packages(<<~TABLE)+ subject | MTWTFSSmtwtf | scheduling mode | predecessors+ new_parent_predecessor | XXX | manual |+ new_parent | XX | automatic | new_parent_predecessor+ predecessor | XXX | manual |+ work_package | XX | automatic | predecessor+ TABLE+ let(:attributes) { { parent: new_parent } }++ it "sets its dates according to its own soonest start and its new parent soonest start" \+ "then it sets parent's dates to be the same as the work package" do+ expect(subject).to be_success+ expect(work_package.reload.parent).to eq new_parent+ expect(subject.all_results.map(&:subject)).to contain_exactly("work_package", "new_parent")++ expect_work_packages(subject.all_results + [new_parent_predecessor, predecessor], <<~TABLE)+ subject | MTWTFSSmtwtf |+ new_parent_predecessor | XXX |+ new_parent | XX |+ predecessor | XXX |+ work_package | XX |+ TABLE+ end+ end++ context "when the work package changes its parent" do+ let_work_packages(<<~TABLE)+ subject | MTWTFSSmtwtf | scheduling mode | predecessors+ new_parent_predecessor | XXX | manual |+ new_parent | XX | automatic | new_parent_predecessor+ old_parent_predecessor | XXX | manual |+ old_parent | XX | automatic | old_parent_predecessor+ work_package | XX | automatic |+ TABLE+ let(:attributes) { { parent: new_parent } }++ it "sets its dates according to its own soonest start and its new parent " \+ "soonest start, not its old parent" do+ expect(subject).to be_success+ expect(work_package.reload.parent).to eq new_parent+ expect(subject.all_results.map(&:subject)).to contain_exactly("work_package")++ expect_work_packages(WorkPackage.all, <<~TABLE)+ subject | MTWTFSSmtwtf | scheduling mode+ new_parent_predecessor | XXX | manual+ new_parent | XX | automatic+ work_package | XX | automatic+ old_parent_predecessor | XXX | manual+ old_parent | XX | automatic+ TABLE+ end+ end++ context "when the work package and the parent being set have different ignore_working_days values" do+ before do+ set_non_working_week_days("saturday", "sunday")+ end++ let_work_packages(<<~TABLE)+ hierarchy | MTWTFSSmt | scheduling mode | days counting | predecessors+ parent_predecessor | XXX | manual | working days only |+ parent | XX | automatic | working days only | parent_predecessor+ wp all days | XX | automatic | working days only |+ # predecessor is here so that work_package can be in automatic scheduling mode+ predecessor | XX | manual | working days only |+ work_package | XX | automatic | all days | predecessor+ TABLE+ let(:attributes) { { parent: } }++ it "calculates correctly the soonest working day for the child using the child's ignore_working_days value" do+ # actually it does not calculate dates correctly in SetAttributesService,+ # but the rescheduling happening later in the UpdateService moves it+ # correctly and updates the parent accordingly+ expect(subject).to be_success+ expect(work_package.reload.parent).to eq parent++ # TODO: "parent" is there twice because it is updated once in the+ # SetScheduleService which sets the parent dates to the children's+ # dates, and once in the UpdateAncestorsService which sets the+ # ignore_non_working_days value. This problem is registered in bug+ # #61758.+ expect(subject.all_results.map(&:subject)).to contain_exactly("work_package", "parent", "parent")++ expect_work_packages(WorkPackage.all, <<~TABLE)+ subject | MTWTFSSmt | scheduling mode | days counting+ parent_predecessor | XXX | manual | working days only+ parent | XXXX | automatic | all days+ wp all days | XX | automatic | working days only+ predecessor | XX | manual | working days only+ work_package | XX | automatic | all days+ TABLE+ end+ end+context "when the work package is automatically scheduled, has a child and no dates" dolet_work_packages(<<~TABLE)hierarchy | MTWTFSS | scheduling mode | predecessors