Skip to content

Commit

Permalink
Merge pull request #15096 from opf/bug/53212-pdf-export-does-not-show…
Browse files Browse the repository at this point in the history
…-parent-ticket-percentcomplete-value

[#53212] PDF export does not show parent ticket %Complete value
  • Loading branch information
as-op committed Mar 25, 2024
2 parents 058e32f + 2a57d3c commit b33b8eb
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 26 deletions.
42 changes: 42 additions & 0 deletions app/models/work_package/exports/formatters/done_ratio.rb
@@ -0,0 +1,42 @@
#-- 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.
#++
module WorkPackage::Exports
module Formatters
class 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 > 0 ? " · Σ #{derived_done_ratio}%" : ""
"#{work_package.done_ratio}%#{derived}"
end
end
end
end
Expand Up @@ -55,7 +55,7 @@ def formatted_hours(value)

def formatted_derived_hours(work_package)
if (derived_estimated_value = work_package.derived_estimated_hours)
"(#{formatted_hours(derived_estimated_value)})"
"· Σ #{formatted_hours(derived_estimated_value)}"
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/initializers/export_formats.rb
Expand Up @@ -13,6 +13,7 @@
formatter WorkPackage, WorkPackage::Exports::Formatters::Days
formatter WorkPackage, WorkPackage::Exports::Formatters::Currency
formatter WorkPackage, WorkPackage::Exports::Formatters::Costs
formatter WorkPackage, WorkPackage::Exports::Formatters::DoneRatio
formatter WorkPackage, Exports::Formatters::CustomField

list Project, Projects::Exports::CSV
Expand Down
Expand Up @@ -325,7 +325,7 @@
it "adapts the datetime fields to the user time zone" do
work_package.reload
estimated_cell = sheet.rows.last.to_a.last
expect(estimated_cell).to eq "(15.0 h)"
expect(estimated_cell).to eq "· Σ 15.0 h"
end
end

Expand All @@ -344,7 +344,7 @@
it "outputs both values" do
work_package.reload
estimated_cell = sheet.rows.last.to_a.last
expect(estimated_cell).to eq "0.0 h (15.0 h)"
expect(estimated_cell).to eq "0.0 h · Σ 15.0 h"
end
end
end
2 changes: 1 addition & 1 deletion spec/models/work_package/exporter/csv_integration_spec.rb
Expand Up @@ -75,6 +75,6 @@
expect(data.last).to include(work_package.description)
expect(data.last).to include(current_user.name)
expect(data.last).to include(work_package.updated_at.localtime.strftime("%m/%d/%Y %I:%M %p"))
expect(data.last).to include("(15.0 h)")
expect(data.last).to include("· Σ 15.0 h")
end
end
Expand Up @@ -63,6 +63,8 @@
type: type_standard,
subject: "Work package 1",
story_points: 1,
done_ratio: 25,
derived_done_ratio: 50,
description: "This is a description",
list_custom_field.attribute_name => [
list_custom_field.value_of("Foo"),
Expand All @@ -75,6 +77,7 @@
parent: work_package_parent,
type: type_bug,
subject: "Work package 2",
done_ratio: 50,
story_points: 2,
description: "This is work package 2",
list_custom_field.attribute_name => list_custom_field.value_of("Foo"))
Expand All @@ -101,21 +104,32 @@
export.export!
end
end
let(:column_names) { %w[id subject status story_points] }
let(:column_names) { %w[id subject status story_points done_ratio] }

def work_packages_sum
work_package_parent.story_points + work_package_child.story_points
end

def work_package_columns(work_package)
[work_package.id.to_s, work_package.subject, work_package.status.name, work_package.story_points.to_s]
[
work_package.id.to_s,
work_package.subject,
work_package.status.name,
work_package.story_points.to_s,
work_package_done_ratio(work_package)
]
end

def work_package_done_ratio(work_package)
work_package.done_ratio == 25 ? "25% · Σ 50%" : "50%"
end

def work_package_details(work_package, index)
["#{index}.", work_package.subject,
column_title(:id), work_package.id.to_s,
column_title(:status), work_package.status.name,
column_title(:story_points), work_package.story_points.to_s,
column_title(:done_ratio), work_package_done_ratio(work_package),
label_title(:description), work_package.description]
end

Expand All @@ -128,27 +142,32 @@ def show
`#{cmd}`
end

subject(:pdf) do
PDF::Inspector::Text.analyze(File.read(export_pdf.content.path))
subject(:pdf_strings) do
# Joining the results for comparison since word wrapping leads to a different array for the same content
PDF::Inspector::Text.analyze(File.read(export_pdf.content.path)).strings.join(" ").squeeze(" ")
end

def pdf_eq_ignore_spacing(strings)
expect(pdf.strings.join(' ')).to eq(strings.join(' '))
end

describe "with a request for a PDF table" do
it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
query.name,
*column_titles,
*work_package_columns(work_package_parent),
*work_package_columns(work_package_child),
"1/1", export_time_formatted, query.name
])
].join(" ")
end
end

describe "with a request for a PDF table grouped" do
let(:query_attributes) { { group_by: "type" } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
query.name,
work_package_parent.type.name,
*column_titles,
Expand All @@ -157,15 +176,15 @@ def show
*column_titles,
*work_package_columns(work_package_child),
"1/1", export_time_formatted, query.name
])
].join(" ")
end
end

describe "with a request for a PDF table grouped with sums" do
let(:query_attributes) { { group_by: "type", display_sums: true } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
query.name,
work_package_parent.type.name,
*column_titles,
Expand All @@ -176,15 +195,15 @@ def show
*work_package_columns(work_package_child),
I18n.t("js.label_sum"), work_package_child.story_points.to_s,
"1/1", export_time_formatted, query.name
])
].join(" ")
end
end

describe "with a request for a PDF table grouped by a custom field with sums" do
let(:query_attributes) { { group_by: list_custom_field.column_name, display_sums: true } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
query.name,
"Foo",
*column_titles,
Expand All @@ -195,15 +214,15 @@ def show
*work_package_columns(work_package_parent),
I18n.t("js.label_sum"), work_package_parent.story_points.to_s,
"1/1", export_time_formatted, query.name
])
].join(" ")
end
end

describe "with a request for a PDF Report" do
let(:options) { { show_report: true } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
*cover_page_content,
query.name,
"1.", "2", work_package_parent.subject,
Expand All @@ -212,7 +231,7 @@ def show
*work_package_details(work_package_parent, "1"),
*work_package_details(work_package_child, "2"),
"2/2", export_time_formatted, query.name
])
].join(" ")
end
end

Expand All @@ -221,7 +240,7 @@ def show
let(:query_attributes) { { show_hierarchies: true } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
*cover_page_content,
query.name,
"1.", "2", work_package_parent.subject,
Expand All @@ -230,7 +249,7 @@ def show
*work_package_details(work_package_parent, "1"),
*work_package_details(work_package_child, "1.1"),
"2/2", export_time_formatted, query.name
])
].join(" ")
end
end

Expand All @@ -239,7 +258,7 @@ def show
let(:query_attributes) { { display_sums: true } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
*cover_page_content,
query.name,
"1.", "2", work_package_parent.subject,
Expand All @@ -251,7 +270,7 @@ def show
*work_package_details(work_package_parent, "1"),
*work_package_details(work_package_child, "2"),
"2/2", export_time_formatted, query.name
])
].join(" ")
end
end

Expand All @@ -260,7 +279,7 @@ def show
let(:query_attributes) { { display_sums: true, group_by: "type" } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
*cover_page_content,
query.name,
"1.", "2", work_package_parent.subject,
Expand All @@ -274,7 +293,7 @@ def show
*work_package_details(work_package_parent, "1"),
*work_package_details(work_package_child, "2"),
"2/2", export_time_formatted, query.name
])
].join(" ")
end
end

Expand All @@ -283,7 +302,7 @@ def show
let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }

it "contains correct data" do
expect(pdf.strings).to eq([
expect(pdf_strings).to eq [
*cover_page_content,
query.name,
"1.", "2", work_package_child.subject,
Expand All @@ -299,7 +318,7 @@ def show
*work_package_details(work_package_child, "1"),
*work_package_details(work_package_parent, "2"),
"2/2", export_time_formatted, query.name
])
].join(" ")
end
end
end

0 comments on commit b33b8eb

Please sign in to comment.