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
Better handle rescheduling with work packages switching to automatic
Christophe Bliard5fef66cca181
diff --git a/app/models/work_packages/scopes/for_scheduling.rb b/app/models/work_packages/scopes/for_scheduling.rbindex 710003f61ea..462e8c339cb 100644--- a/app/models/work_packages/scopes/for_scheduling.rb+++ b/app/models/work_packages/scopes/for_scheduling.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -233,7 +235,10 @@ module WorkPackages::ScopesLEFT JOIN LATERAL (SELECTdescendant_hierarchies.ancestor_id from_id,- bool_and(COALESCE(descendant_work_packages.schedule_manually, false)) manually+ bool_and(+ COALESCE(descendant_work_packages.schedule_manually, false)+ AND (NOT EXISTS (SELECT 1 FROM switching_to_automatic_mode WHERE descendant_work_packages.id = switching_to_automatic_mode.id))+ ) manuallyFROM work_package_hierarchies descendant_hierarchiesJOIN work_packages descendant_work_packagesONdiff --git a/spec/models/work_packages/scopes/for_scheduling_spec.rb b/spec/models/work_packages/scopes/for_scheduling_spec.rbindex ba81c895e30..bf102e5e921 100644--- a/spec/models/work_packages/scopes/for_scheduling_spec.rb+++ b/spec/models/work_packages/scopes/for_scheduling_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -341,6 +343,28 @@ RSpec.describe WorkPackages::Scopes::ForScheduling, "allowed scope" doendend+ context "for a work package with a manually scheduled successor which has a parent" do+ let!(:existing_work_packages) { [successor, successor_parent] }++ before do+ successor.update_column(:schedule_manually, true)+ end++ context "with the successor keeping its manual scheduling" do+ it "is empty" do+ expect(WorkPackage.for_scheduling([origin]))+ .to be_empty+ end+ end++ context "with the successor switching to automatic scheduling (like when the relation is created)" do+ it "consists of the successor and its parent" do+ expect(WorkPackage.for_scheduling([origin], switching_to_automatic_mode: [successor]))+ .to contain_exactly(successor, successor_parent)+ end+ end+ end+context "for a work package with a successor with two children and the successor having a successor" dolet!(:existing_work_packages) { [successor, successor_child, successor_child2, successor_successor] }diff --git a/spec/services/relations/create_service_integration_spec.rb b/spec/services/relations/create_service_integration_spec.rbnew file mode 100644index 00000000000..7b75c26dbfd--- /dev/null+++ b/spec/services/relations/create_service_integration_spec.rb@@ -0,0 +1,80 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++RSpec.describe Relations::CreateService do+ create_shared_association_defaults_for_work_package_factory++ shared_let(:user) { create(:admin) }++ let(:instance) { described_class.new(user:) }++ subject { instance.call(attributes) }++ before do+ set_non_working_week_days("saturday", "sunday")+ end++ context "when creating a successor relation to a child with an indirect predecessor" do+ let_work_packages(<<~TABLE)+ | hierarchy | MTWTFSS | scheduling mode | predecessors+ | parent_predecessor | XXX | manual |+ | parent | X..XX | automatic | parent_predecessor+ | child | X..XX | manual |+ # this will become the predecessor of the child+ | child_predecessor | X | manual |+ TABLE+ let(:attributes) do+ {+ "relation_type" => "follows",+ "from_id" => child.id,+ "to_id" => child_predecessor.id+ }+ end++ it "reschedules child and parent to start right after the indirect predecessor" do+ expect(subject).to be_success+ relation = subject.result+ expect(relation.predecessor).to eq(child_predecessor)+ expect(relation.successor).to eq(child)+ expect(subject.all_results).to contain_exactly(relation, child, parent)++ expect_work_packages_after_reload([parent_predecessor, parent, child, child_predecessor], <<~TABLE)+ | subject | MTWTFSS | scheduling mode+ | parent_predecessor | XXX | manual+ | child_predecessor | X | manual+ | parent | XX..X | automatic+ | child | XX..X | automatic+ # this will become the predecessor of the child+ TABLE+ end+ end+end