mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
[#42761] Date formatting in XLS export from Cost Report is wrong
https://community.openproject.org/work_packages/42761
This commit is contained in:
@@ -41,7 +41,8 @@ class OpenProject::Reporting::CostEntryXlsTable < OpenProject::XlsExport::XlsVie
|
||||
|
||||
def build_cost_rows
|
||||
sorted_results.each do |result|
|
||||
spreadsheet.add_row(cost_row(result))
|
||||
row = spreadsheet.add_row(cost_row(result))
|
||||
row.set_format 0, date_format
|
||||
end
|
||||
end
|
||||
|
||||
@@ -73,7 +74,7 @@ class OpenProject::Reporting::CostEntryXlsTable < OpenProject::XlsExport::XlsVie
|
||||
end
|
||||
|
||||
def cost_main_columns(result)
|
||||
main_cols = [show_field(:spent_on, result.fields["spent_on"])]
|
||||
main_cols = [result.fields["spent_on"].to_date]
|
||||
main_cols.concat cost_main_times_columns(result) if with_times_column?
|
||||
main_cols
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ require_relative "support/pages/cost_report_page"
|
||||
|
||||
RSpec.describe "Cost reports XLS export", :js do
|
||||
shared_let(:project) { create(:project) }
|
||||
shared_let(:user) { create(:admin) }
|
||||
shared_let(:user) { create(:admin, preferences: { time_zone: "UTC" }) }
|
||||
shared_let(:cost_type) { create(:cost_type, name: "Post-war", unit: "cap", unit_plural: "caps") }
|
||||
shared_let(:work_package) { create(:work_package, project:, subject: "Some task") }
|
||||
shared_let(:cost_entry) do
|
||||
@@ -72,9 +72,13 @@ RSpec.describe "Cost reports XLS export", :js do
|
||||
DownloadList.clear
|
||||
end
|
||||
|
||||
def expect_custom_cost_entry(cost_entry_row)
|
||||
def excel_float_to_date(excel_float)
|
||||
(DateTime.new(1899, 12, 30) + excel_float).to_date
|
||||
end
|
||||
|
||||
def expect_custom_cost_entry(cost_entry_row, entry)
|
||||
date, user_ref, _, wp_ref, _, project_ref, costs, type, = cost_entry_row
|
||||
expect(date).to eq(cost_entry.spent_on.iso8601)
|
||||
expect(excel_float_to_date(date)).to eq(entry.spent_on)
|
||||
expect(user_ref).to eq(user.name)
|
||||
expect(wp_ref).to include "Some task"
|
||||
expect(project_ref).to eq project.name
|
||||
@@ -84,7 +88,7 @@ RSpec.describe "Cost reports XLS export", :js do
|
||||
|
||||
def expect_labor_cost_entry(cost_entry_row, entry)
|
||||
date, user_ref, _, wp_ref, _, project_ref, costs, type, = cost_entry_row
|
||||
expect(date).to eq(entry.spent_on.iso8601)
|
||||
expect(excel_float_to_date(date)).to eq(entry.spent_on)
|
||||
expect(user_ref).to eq(user.name)
|
||||
expect(wp_ref).to include "Some task"
|
||||
expect(project_ref).to eq project.name
|
||||
@@ -94,7 +98,7 @@ RSpec.describe "Cost reports XLS export", :js do
|
||||
|
||||
def expect_time_entry(time_entry_row, entry, start_time_value, end_time_value)
|
||||
date, start_time, end_time, user_ref, _, wp_ref, _, project_ref, costs, type, = time_entry_row
|
||||
expect(date).to eq(entry.spent_on.iso8601)
|
||||
expect(excel_float_to_date(date)).to eq(entry.spent_on)
|
||||
expect(start_time).to eq start_time_value
|
||||
expect(end_time).to eq end_time_value
|
||||
expect(user_ref).to eq(user.name)
|
||||
@@ -111,7 +115,7 @@ RSpec.describe "Cost reports XLS export", :js do
|
||||
def expect_cost_entries_sheet
|
||||
title, _, cost_entry_row, time_entry_row, time_entry_long_row = subject.first.rows
|
||||
expect_sheet_title title
|
||||
expect_custom_cost_entry cost_entry_row
|
||||
expect_custom_cost_entry cost_entry_row, cost_entry
|
||||
expect_labor_cost_entry time_entry_row, time_entry
|
||||
expect_labor_cost_entry time_entry_long_row, time_entry_long
|
||||
end
|
||||
@@ -130,9 +134,9 @@ RSpec.describe "Cost reports XLS export", :js do
|
||||
end
|
||||
|
||||
def expect_custom_type_entries_sheet
|
||||
title, _, cost_entry = subject.third.rows
|
||||
title, _, cost_entry_row = subject.third.rows
|
||||
expect_sheet_title title
|
||||
expect_custom_cost_entry cost_entry
|
||||
expect_custom_cost_entry cost_entry_row, cost_entry
|
||||
end
|
||||
|
||||
def export_xls
|
||||
|
||||
@@ -69,6 +69,14 @@ class OpenProject::XlsExport::XlsViews
|
||||
"0.00"
|
||||
end
|
||||
|
||||
def date_format
|
||||
@date_format ||= Spreadsheet::Format.new(
|
||||
number_format: "yyyy-mm-dd",
|
||||
horizontal_align: :left,
|
||||
vertical_align: :top
|
||||
)
|
||||
end
|
||||
|
||||
def project_representation(value)
|
||||
ar_presentation(Project, value, &:name)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user