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
Copying a work package copies over the % Complete value
Christophe Bliardaf63a36e75b3
diff --git a/app/contracts/work_packages/copy_contract.rb b/app/contracts/work_packages/copy_contract.rbnew file mode 100644index 00000000000..4bd8d5e895b--- /dev/null+++ b/app/contracts/work_packages/copy_contract.rb@@ -0,0 +1,40 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 "work_packages/create_contract"++module WorkPackages+ class CopyContract < CreateContract+ # As % Complete can be set while Work and Remaining work are not, copying is+ # a scenario where this field must be writable+ attribute :done_ratio,+ writable: true+ end+enddiff --git a/app/contracts/work_packages/copy_project_contract.rb b/app/contracts/work_packages/copy_project_contract.rbindex 5aa7993f1fd..a9d49288287 100644--- a/app/contracts/work_packages/copy_project_contract.rb+++ b/app/contracts/work_packages/copy_project_contract.rb@@ -26,14 +26,14 @@# See COPYRIGHT and LICENSE files for more details.#++-require "work_packages/create_contract"+require "work_packages/copy_contract"# Can be used to copy all of a project's work packages. As the# work packages can be old, some of the validations that would# apply to newly created work packages need not apply there, e.g# on copying, it is ok for work packages to have closed versionsmodule WorkPackages- class CopyProjectContract < CreateContract+ class CopyProjectContract < CopyContractinclude WorkPackages::SkipAuthorizationChecks# let the contract be used in error messagesdiff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rbindex 8fb079cc19c..1256342f332 100644--- a/app/services/work_packages/copy_service.rb+++ b/app/services/work_packages/copy_service.rb@@ -35,7 +35,7 @@ class WorkPackages::CopyService:work_package,:contract_class- def initialize(user:, work_package:, contract_class: WorkPackages::CreateContract)+ def initialize(user:, work_package:, contract_class: WorkPackages::CopyContract)self.user = userself.work_package = work_packageself.contract_class = contract_classdiff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rbindex d4e94b2c031..2588d22479e 100644--- a/spec/services/work_packages/copy_service_integration_spec.rb+++ b/spec/services/work_packages/copy_service_integration_spec.rb@@ -164,6 +164,36 @@ RSpec.describe WorkPackages::CopyService, "integration", type: :model doendend+ context "with work, remaining work, and % complete set in the source work package" do+ before do+ work_package.update(+ estimated_hours: 10.0,+ remaining_hours: 6.0,+ done_ratio: 40+ )+ end++ it "copies them all values over" do+ expect(copy.estimated_hours).to eq(10.0)+ expect(copy.remaining_hours).to eq(6.0)+ expect(copy.done_ratio).to eq(40)+ end+ end++ context "with only % complete set in the source work package" do+ before do+ work_package.update(+ estimated_hours: nil,+ remaining_hours: nil,+ done_ratio: 40+ )+ end++ it "copies the % complete value over" do+ expect(copy.done_ratio).to eq(40)+ end+ end+describe "#attributes" dobefore dotarget_project.types << work_package.type