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
[63739] Add derived % complete as additional column in XLS and CSV exports
Christophe Bliardfb65d96e0dec
diff --git a/app/models/work_package/exports/additional_columns.rb b/app/models/work_package/exports/additional_columns.rbindex d6893f2f349..0cda289aa86 100644--- a/app/models/work_package/exports/additional_columns.rb+++ b/app/models/work_package/exports/additional_columns.rb@@ -35,7 +35,8 @@ module WorkPackage::Exportsmodule AdditionalColumnsADDITIONAL_COLUMNS = {estimated_hours: [:derived_estimated_hours],- remaining_hours: [:derived_remaining_hours]+ remaining_hours: [:derived_remaining_hours],+ done_ratio: [:derived_done_ratio]}.freezedef get_columnsdiff --git a/app/models/work_package/exports/formatters/compound_done_ratio.rb b/app/models/work_package/exports/formatters/compound_done_ratio.rbnew file mode 100644index 00000000000..a0989bb85d0--- /dev/null+++ b/app/models/work_package/exports/formatters/compound_done_ratio.rb@@ -0,0 +1,50 @@+# 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.+#+++module WorkPackage::Exports+ module Formatters+ class CompoundDoneRatio < ::Exports::Formatters::Default+ def self.apply?(name, export_format)+ name.to_sym == :done_ratio && export_format == :pdf+ end++ def format(work_package, **)+ derived_done_ratio = work_package.derived_done_ratio+ derived = derived_done_ratio&.positive? ? " · Σ #{format_value(derived_done_ratio)}" : ""+ "#{format_value(work_package.done_ratio)}#{derived}"+ end++ def format_value(value, _options = {})+ return "" if value.nil?++ "#{value}%"+ end+ end+ end+enddiff --git a/app/models/work_package/exports/formatters/done_ratio.rb b/app/models/work_package/exports/formatters/done_ratio.rbindex e84757523f4..9ace5fb909a 100644--- a/app/models/work_package/exports/formatters/done_ratio.rb+++ b/app/models/work_package/exports/formatters/done_ratio.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -28,14 +30,8 @@module WorkPackage::Exportsmodule Formattersclass DoneRatio < ::Exports::Formatters::Default- def self.apply?(name, _export_format)- name.to_sym == :done_ratio- end-- def format(work_package, **)- derived_done_ratio = work_package.derived_done_ratio- derived = derived_done_ratio&.positive? ? " · Σ #{format_value(derived_done_ratio)}" : ""- "#{format_value(work_package.done_ratio)}#{derived}"+ def self.apply?(name, export_format)+ name.to_sym.in?(%i[done_ratio derived_done_ratio]) && export_format != :pdfenddef format_value(value, _options = {})diff --git a/config/initializers/export_formats.rb b/config/initializers/export_formats.rbindex 30255e822d5..ccc88313ed7 100644--- a/config/initializers/export_formats.rb+++ b/config/initializers/export_formats.rb@@ -1,3 +1,33 @@+# 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.+#+++Rails.application.configure do |application|application.config.to_prepare doExports::Register.register do@@ -12,6 +42,7 @@ Rails.application.configure do |application|formatter WorkPackage, WorkPackage::Exports::Formatters::Daysformatter WorkPackage, WorkPackage::Exports::Formatters::Currencyformatter WorkPackage, WorkPackage::Exports::Formatters::Costs+ formatter WorkPackage, WorkPackage::Exports::Formatters::CompoundDoneRatioformatter WorkPackage, WorkPackage::Exports::Formatters::DoneRatioformatter WorkPackage, WorkPackage::Exports::Formatters::Dateformatter WorkPackage, Exports::Formatters::CustomFielddiff --git a/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb b/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rbindex 25723cbf0a3..ad5ae1af501 100644--- a/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb+++ b/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb@@ -223,7 +223,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendend- it "includes estimated hours" do+ it "includes work" doexpect(sheet.rows.size).to eq(4 + 1)# Check row after header row@@ -232,7 +232,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendcontext "with duration format being set to 'days and hours'", with_settings: { duration_format: "days_and_hours" } do- it "includes estimated hours unformatted" do+ it "includes work unformatted" doexpect(sheet.rows.size).to eq(4 + 1)# Check row after header row@@ -316,7 +316,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendend- describe "with derived estimated hours only" do+ describe "with total work only" dolet(:work_package) docreate(:work_package,project:,@@ -325,7 +325,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendlet(:work_packages) { [work_package] }- let(:column_names) { %w[estimated_hours remaining_hours] }+ let(:column_names) { %w[estimated_hours remaining_hours done_ratio] }it "outputs its raw value in an additional 'Total work' column right after the 'Work' column" doheaders_row, values_row = sheet.rows@@ -335,12 +335,14 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do["Work", nil],["Total work", "15.0"],["Remaining work", nil],- ["Total remaining work", nil]+ ["Total remaining work", nil],+ ["% Complete", nil],+ ["Total % complete", nil]]endend- describe "with estimated hours, derived estimated hours, remaining hours, and derived remaining hours" do+ describe "with work, total work, remaining work, total remaining work, % complete, and total % complete" dolet(:work_package) docreate(:work_package,project:,@@ -348,13 +350,15 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doderived_estimated_hours: 15.0,remaining_hours: 5.0,derived_remaining_hours: 8.0,+ done_ratio: 50,+ derived_done_ratio: 75,type: project.types.first)endlet(:work_packages) { [work_package] }- let(:column_names) { %w[estimated_hours remaining_hours] }+ let(:column_names) { %w[estimated_hours remaining_hours done_ratio] }- it "outputs all raw values in 4 distinct columns" do+ it "outputs all raw values in distinct columns for own and total values" doheaders_row, values_row = sheet.rows# why is there a nil at the end of the headers row?headers_row.compact!@@ -362,12 +366,14 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do["Work", "10.0"],["Total work", "15.0"],["Remaining work", "5.0"],- ["Total remaining work", "8.0"]+ ["Total remaining work", "8.0"],+ ["% Complete", "50%"],+ ["Total % complete", "75%"]]endend- describe "with estimated and remaining hours set to zero and their derived value set" do+ describe "with work, remaining work, and % complete set to zero and their total values set" dolet(:work_package) docreate(:work_package,project:,@@ -375,13 +381,15 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doderived_estimated_hours: 15.0,remaining_hours: 0.0,derived_remaining_hours: 8,+ done_ratio: 0,+ derived_done_ratio: 42,type: project.types.first)endlet(:work_packages) { [work_package] }- let(:column_names) { %w[estimated_hours remaining_hours] }+ let(:column_names) { %w[estimated_hours remaining_hours done_ratio] }- it "outputs raw values in 4 distinct columns" do+ it "outputs raw values in distinct columns for own and total values" doheaders_row, values_row = sheet.rows# why is there a nil at the end of the headers row?headers_row.compact!@@ -389,7 +397,9 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do["Work", "0.0"],["Total work", "15.0"],["Remaining work", "0.0"],- ["Total remaining work", "8.0"]+ ["Total remaining work", "8.0"],+ ["% Complete", "0%"],+ ["Total % complete", "42%"]]endenddiff --git a/spec/models/work_package/exports/formatters/done_ratio_spec.rb b/spec/models/work_package/exports/formatters/compound_done_ratio_spec.rbsimilarity index 97%rename from spec/models/work_package/exports/formatters/done_ratio_spec.rbrename to spec/models/work_package/exports/formatters/compound_done_ratio_spec.rbindex d0aa2c50f9f..ae6a7d8d5b7 100644--- a/spec/models/work_package/exports/formatters/done_ratio_spec.rb+++ b/spec/models/work_package/exports/formatters/compound_done_ratio_spec.rb@@ -30,7 +30,7 @@require "spec_helper"-RSpec.describe WorkPackage::Exports::Formatters::DoneRatio do+RSpec.describe WorkPackage::Exports::Formatters::CompoundDoneRatio dosubject { described_class.new(:done_ratio) }describe "#format" do