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

[63739] do not format work and remaining work for xls and csv exports

Christophe Bliarde84def8b120a
diff --git a/app/models/work_package/exports/formatters/compound_hours.rb b/app/models/work_package/exports/formatters/compound_hours.rb
index c7f74b03eef..336af54299e 100644
--- a/app/models/work_package/exports/formatters/compound_hours.rb
+++ b/app/models/work_package/exports/formatters/compound_hours.rb
@@ -28,8 +28,8 @@
module WorkPackage::Exports
module Formatters
class CompoundHours < ::Exports::Formatters::Default
- def self.apply?(name, _export_format)
- name.to_sym == key
+ def self.apply?(name, export_format)
+ name.to_sym.in?(%i[estimated_hours remaining_hours]) && export_format == :pdf
end
def format(work_package, **)
@@ -45,10 +45,6 @@ module WorkPackage::Exports
private
- def attribute
- self.class.key
- end
-
def total_prefix(value)
value && "· Σ #{value}"
end
diff --git a/app/models/work_package/exports/formatters/estimated_hours.rb b/app/models/work_package/exports/formatters/estimated_hours.rb
deleted file mode 100644
index 2746de765d9..00000000000
--- a/app/models/work_package/exports/formatters/estimated_hours.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#-- 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 EstimatedHours < ::WorkPackage::Exports::Formatters::CompoundHours
- end
- end
-end
diff --git a/app/models/work_package/exports/formatters/remaining_hours.rb b/app/models/work_package/exports/formatters/remaining_hours.rb
deleted file mode 100644
index c46434b7abd..00000000000
--- a/app/models/work_package/exports/formatters/remaining_hours.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#-- 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 RemainingHours < ::WorkPackage::Exports::Formatters::CompoundHours
- end
- end
-end
diff --git a/config/initializers/export_formats.rb b/config/initializers/export_formats.rb
index 2883730b622..30255e822d5 100644
--- a/config/initializers/export_formats.rb
+++ b/config/initializers/export_formats.rb
@@ -6,8 +6,7 @@ Rails.application.configure do |application|
single WorkPackage, WorkPackage::PDFExport::WorkPackageToPdf
- formatter WorkPackage, WorkPackage::Exports::Formatters::EstimatedHours
- formatter WorkPackage, WorkPackage::Exports::Formatters::RemainingHours
+ formatter WorkPackage, WorkPackage::Exports::Formatters::CompoundHours
formatter WorkPackage, WorkPackage::Exports::Formatters::SpentUnits
formatter WorkPackage, WorkPackage::Exports::Formatters::Hours
formatter WorkPackage, WorkPackage::Exports::Formatters::Days
diff --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.rb
index 9e79822d749..f29bf999bfe 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
@@ -228,7 +228,17 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do
# Check row after header row
hours = sheet.rows[1].values_at(2)
- expect(hours).to include("27.5h")
+ expect(hours).to include("27.5")
+ end
+
+ context "with duration format being set to 'days and hours'", with_settings: { duration_format: "days_and_hours" } do
+ it "includes estimated hours unformatted" do
+ expect(sheet.rows.size).to eq(4 + 1)
+
+ # Check row after header row
+ hours = sheet.rows[1].values_at(2)
+ expect(hours).to include("27.5")
+ end
end
end
@@ -306,7 +316,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do
end
end
- describe "with derived estimated hours" do
+ describe "with derived estimated hours only" do
let(:work_package) do
create(:work_package,
project:,
@@ -317,10 +327,29 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do
let(:column_names) { %w[subject status updated_at estimated_hours] }
- it "adapts the datetime fields to the user time zone" do
+ it "does not output anything" do
+ work_package.reload
+ estimated_cell = sheet.rows.last.to_a.last
+ expect(estimated_cell).to be_nil
+ end
+ end
+
+ describe "with estimated hours and derived estimated hours" do
+ let(:work_package) do
+ create(:work_package,
+ project:,
+ estimated_hours: 10.0,
+ derived_estimated_hours: 15.0,
+ type: project.types.first)
+ end
+ let(:work_packages) { [work_package] }
+
+ let(:column_names) { %w[subject status updated_at estimated_hours] }
+
+ it "outputs only the unformatted estimated hours" do
work_package.reload
estimated_cell = sheet.rows.last.to_a.last
- expect(estimated_cell).to eq "· Σ 15h"
+ expect(estimated_cell).to eq "10.0"
end
end
@@ -338,11 +367,11 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS do
let(:column_names) { %w[subject status updated_at estimated_hours remaining_hours] }
- it "outputs both values" do
+ it "outputs the unformatted values without the derived values" do
work_package.reload
estimated_cell, remaining_cell = sheet.rows.last.to_a.last(2)
- expect(estimated_cell).to eq "0h · Σ 15h"
- expect(remaining_cell).to eq "0h · Σ 8h"
+ expect(estimated_cell).to eq "0.0"
+ expect(remaining_cell).to eq "0.0"
end
end
end
diff --git a/spec/models/work_package/exporter/csv_integration_spec.rb b/spec/models/work_package/exporter/csv_integration_spec.rb
index c09f23e1657..db0f5576aac 100644
--- a/spec/models/work_package/exporter/csv_integration_spec.rb
+++ b/spec/models/work_package/exporter/csv_integration_spec.rb
@@ -67,6 +67,7 @@ RSpec.describe WorkPackage::Exports::CSV, "integration" do
subject: "Ruby encodes ß as '\\xDF' in ISO-8859-1.",
description: "\u2022 requires unicode.",
assigned_to: user,
+ estimated_hours: 10.0,
derived_estimated_hours: 15.0,
type: type_a,
project:
@@ -85,7 +86,7 @@ RSpec.describe WorkPackage::Exports::CSV, "integration" do
expect(data.last).to include(work_package.description)
expect(data.last).to include(user.name)
expect(data.last).to include(work_package.updated_at.in_time_zone(user.time_zone).strftime("%m/%d/%Y %I:%M %p"))
- expect(data.last).to include("· Σ 15h")
+ expect(data.last).to include("10.0")
end
end
@@ -103,7 +104,7 @@ RSpec.describe WorkPackage::Exports::CSV, "integration" do
expect(data.last).not_to include(work_package.description)
expect(data.last).to include(user.name)
expect(data.last).to include(work_package.updated_at.in_time_zone(user.time_zone).strftime("%m/%d/%Y %I:%M %p"))
- expect(data.last).to include("· Σ 15h")
+ expect(data.last).to include("10.0")
end
end
end