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
[#67907] Wrong cell format in XLS export do not allow for calculations
Dombi Attilaf7ef779cdff7
diff --git a/app/models/exports/formatters/default.rb b/app/models/exports/formatters/default.rbindex 718c97bbd0b..ab0a56a5af5 100644--- a/app/models/exports/formatters/default.rb+++ b/app/models/exports/formatters/default.rb@@ -79,6 +79,14 @@ module Exports{}end+ def currency_format+ "#,##0.00 [$#{Setting.costs_currency}]"+ end++ def number_format+ "0.00"+ end+protected# By default, use try as a non-destructive accessordiff --git a/app/models/work_package/exports/formatters/work_hours.rb b/app/models/work_package/exports/formatters/work_hours.rbnew file mode 100644index 00000000000..63c9a28f6ca--- /dev/null+++ b/app/models/work_package/exports/formatters/work_hours.rb@@ -0,0 +1,43 @@+# 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 WorkHours < ::Exports::Formatters::Default+ def self.apply?(name, export_format)+ %i[estimated_hours remaining_hours].include?(name.to_sym) && export_format == :csv+ end++ def format_options+ { number_format: }+ end+ end+ end+enddiff --git a/config/initializers/export_formats.rb b/config/initializers/export_formats.rbindex 4a9081172ac..3cb7abf4c40 100644--- a/config/initializers/export_formats.rb+++ b/config/initializers/export_formats.rb@@ -48,6 +48,7 @@ Rails.application.configure do |application|formatter WorkPackage, WorkPackage::Exports::Formatters::Hoursformatter WorkPackage, WorkPackage::Exports::Formatters::ProjectPhaseformatter WorkPackage, WorkPackage::Exports::Formatters::SpentUnits+ formatter WorkPackage, WorkPackage::Exports::Formatters::WorkHourslist Project, Projects::Exports::CSVlist Project, Projects::Exports::PDFdiff --git a/modules/budgets/app/models/projects/exports/formatters/budget_currency_attribute.rb b/modules/budgets/app/models/projects/exports/formatters/budget_currency_attribute.rbindex 068423fd672..00924a4ec4d 100644--- a/modules/budgets/app/models/projects/exports/formatters/budget_currency_attribute.rb+++ b/modules/budgets/app/models/projects/exports/formatters/budget_currency_attribute.rb@@ -49,11 +49,11 @@ module Projects::Exports::Formattersbudgets_attribute = BudgetCurrencyAttribute.budget_mapping.fetch(attribute.to_sym)return unless project_budgets && budgets_attribute- budget_format(project_budgets.public_send(budgets_attribute))+ project_budgets.public_send(budgets_attribute)end- def budget_format(value)- number_to_currency(value, precision: 0)+ def format_options+ { number_format: currency_format }endendenddiff --git a/modules/budgets/spec/models/projects/exports/formatters/budget_currency_attribute_spec.rb b/modules/budgets/spec/models/projects/exports/formatters/budget_currency_attribute_spec.rbindex 3157753f3ec..f3a84662e56 100644--- a/modules/budgets/spec/models/projects/exports/formatters/budget_currency_attribute_spec.rb+++ b/modules/budgets/spec/models/projects/exports/formatters/budget_currency_attribute_spec.rb@@ -89,25 +89,43 @@ RSpec.describe Projects::Exports::Formatters::BudgetCurrencyAttribute doUser.current = user_with_permissionend- it "formats the budget available" do+ it "returns the raw budget available value" doallow(project_budgets_double).to receive(:total_available).and_return(42.7)instance = described_class.new(:budget_available)- expect(instance.format(project)).to eq("43 EUR")+ expect(instance.format(project)).to eq(42.7)end- it "formats the budget spent" do+ it "returns the raw budget spent value" doallow(project_budgets_double).to receive(:total_spent).and_return(42.7)instance = described_class.new(:budget_spent)- expect(instance.format(project)).to eq("43 EUR")+ expect(instance.format(project)).to eq(42.7)end- it "formats the budget planned" do+ it "returns the raw budget planned value" doallow(project_budgets_double).to receive(:total_planned).and_return(42.7)instance = described_class.new(:budget_planned)- expect(instance.format(project)).to eq("43 EUR")+ expect(instance.format(project)).to eq(42.7)+ end+ end+ end++ describe "#format_options" do+ let(:instance) { described_class.new(:budget_available) }++ it "returns currency format options" do+ with_settings(costs_currency: "USD", costs_currency_format: "%n %u") do+ expected_format = "#,##0.00 [$USD]"+ expect(instance.format_options).to eq({ number_format: expected_format })+ end+ end++ it "handles different currency settings" do+ with_settings(costs_currency: "EUR", costs_currency_format: "%u %n") do+ expected_format = "[$EUR] #,##0.00"+ expect(instance.format_options).to eq({ number_format: expected_format })endendenddiff --git a/spec/models/work_package/exports/formatters/work_hours_spec.rb b/spec/models/work_package/exports/formatters/work_hours_spec.rbnew file mode 100644index 00000000000..dc1a3a32984--- /dev/null+++ b/spec/models/work_package/exports/formatters/work_hours_spec.rb@@ -0,0 +1,63 @@+# 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 WorkPackage::Exports::Formatters::WorkHours do+ let(:formatter_instance) { described_class.new(:estimated_hours) }++ describe ".apply?" do+ it "returns true for estimated_hours and csv format" do+ expect(described_class.apply?(:estimated_hours, :csv)).to be true+ end++ it "returns true for remaining_hours and csv format" do+ expect(described_class.apply?(:remaining_hours, :csv)).to be true+ end++ it "returns false for spent_hours and csv format" do+ expect(described_class.apply?(:spent_hours, :csv)).to be false+ end++ it "returns false for estimated_hours and pdf format" do+ expect(described_class.apply?(:estimated_hours, :pdf)).to be false+ end++ it "returns false for other attributes" do+ expect(described_class.apply?(:other_attribute, :csv)).to be false+ end+ end++ describe "#format_options" do+ it "returns number format for hours" do+ expect(formatter_instance.format_options).to eq({ number_format: "0.00" })+ end+ end+end