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

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.rb
new file mode 100644
index 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
+end
diff --git a/app/contracts/work_packages/copy_project_contract.rb b/app/contracts/work_packages/copy_project_contract.rb
index 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 versions
module WorkPackages
- class CopyProjectContract < CreateContract
+ class CopyProjectContract < CopyContract
include WorkPackages::SkipAuthorizationChecks
# let the contract be used in error messages
diff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rb
index 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 = user
self.work_package = work_package
self.contract_class = contract_class
diff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rb
index 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 do
end
end
+ 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" do
before do
target_project.types << work_package.type