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
Fix Excel export of costs
Klaus Zanders8a8a1ad1e1ed
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex 39e1516380f..02fb85e1d66 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -125,6 +125,10 @@ class TimeEntry < ApplicationRecordendend+ def entity_gid+ entity&.to_gid.to_s+ end+def hours=(value)super(value.is_a?(String) ? (value.to_hours || value) : value)enddiff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex 0861ba1bf57..cee5a4b959f 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -40,7 +40,6 @@ en:spent: "Spent"spent_on: "Date"logged_by: "Logged by"- entity: Entitycost_type:unit: "Unit name"unit_plural: "Pluralized unit name"@@ -59,7 +58,6 @@ en:time_entry:project: Projectuser: User- entity: Entitywork_package: Work packagesubject: Subjecthours: Hours@@ -101,6 +99,9 @@ en:units: "Units"valid_from: "Valid from"fixed_date: "Fixed date"+ entity: Entity+ entity_id: Entity+ entity_gid: Entitybutton_add_rate: "Add rate"button_log_costs: "Log unit costs"diff --git a/modules/reporting/app/helpers/reporting_helper.rb b/modules/reporting/app/helpers/reporting_helper.rbindex c102eaba1ab..a834a2ead19 100644--- a/modules/reporting/app/helpers/reporting_helper.rb+++ b/modules/reporting/app/helpers/reporting_helper.rb@@ -121,9 +121,15 @@ module ReportingHelperbudget_link valuewhen :work_package_idlink_to_work_package(WorkPackage.find(value.to_i))- when :entity_id # rubocop:disable Lint/DuplicateBranch- # TODO: Add ability to use other resources here as well- link_to_work_package(WorkPackage.find(value.to_i))+ when :entity_gid+ # TODO: All possible time entry associations need to be checked here+ entity = GlobalID::Locator.locate(value, only: TimeEntry::ALLOWED_ENTITY_TYPES.map(&:safe_constantize))+ if entity.is_a?(WorkPacakge)+ link_to_work_package(entity)+ else+ # TODO proper other links+ entity.inspect+ endwhen :entity_type# TODO: Skip for nownildiff --git a/modules/reporting/app/models/cost_query/result.rb b/modules/reporting/app/models/cost_query/result.rbindex 1f0a309aa6e..41e8328b254 100644--- a/modules/reporting/app/models/cost_query/result.rb+++ b/modules/reporting/app/models/cost_query/result.rb@@ -68,6 +68,11 @@ class CostQuery::Result < Report::Resultstart + self["units"].to_f.hoursend+ def entity_gid+ # TODO: Find if there is a better way to generate the entity GID+ "gid://#{GlobalID.app}/#{self['entity_type']}/#{self['entity_id']}"+ end+privatedef timestamp(date, time, time_zone)diff --git a/modules/reporting/lib/open_project/reporting/cost_entry_xls_table.rb b/modules/reporting/lib/open_project/reporting/cost_entry_xls_table.rbindex 52f3e06cb0e..fb15801fcd9 100644--- a/modules/reporting/lib/open_project/reporting/cost_entry_xls_table.rb+++ b/modules/reporting/lib/open_project/reporting/cost_entry_xls_table.rb@@ -80,6 +80,8 @@ class OpenProject::Reporting::CostEntryXlsTable < OpenProject::XlsExport::XlsViedef cost_row(result)current_cost_type_id = result.fields["cost_type_id"].to_i+ # TODO: What would be the correct way here?+ result.fields["entity_gid"] = result.entity_gidcost_main_columns(result).concat(cost_fields_columns(result))@@ -125,7 +127,7 @@ class OpenProject::Reporting::CostEntryXlsTable < OpenProject::XlsExport::XlsVieenddef cost_entry_attributes- %i[user_id activity_id work_package_id comments project_id]+ %i[user_id activity_id entity_gid comments project_id]end# Returns the results of the query sorted by date the time was spent on and by iddiff --git a/modules/reporting/spec/features/export_cost_report_spec.rb b/modules/reporting/spec/features/export_cost_report_spec.rbindex 09dc85507bf..e407dfd35d0 100644--- a/modules/reporting/spec/features/export_cost_report_spec.rb+++ b/modules/reporting/spec/features/export_cost_report_spec.rb@@ -37,18 +37,18 @@ RSpec.describe "Cost reports XLS export", :js doshared_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- create(:cost_entry, user:, work_package:, project:,+ create(:cost_entry, user:, entity: work_package, project:,cost_type:, spent_on: 3.days.ago)endshared_let(:time_entry) do- create(:time_entry, user:, work_package:, project:,+ create(:time_entry, user:, entity: work_package, project:,start_time: 1 * 60,spent_on: 2.days.ago,hours: 1.95,time_zone: "UTC")endshared_let(:time_entry_long) do- create(:time_entry, user:, work_package:, project:,+ create(:time_entry, user:, entity: work_package, project:,start_time: 1 * 60,spent_on: 1.day.ago,hours: 28.0,diff --git a/modules/xls_export/lib/open_project/xls_export/xls_views.rb b/modules/xls_export/lib/open_project/xls_export/xls_views.rbindex d3b038de2a2..5d18da1a37e 100644--- a/modules/xls_export/lib/open_project/xls_export/xls_views.rb+++ b/modules/xls_export/lib/open_project/xls_export/xls_views.rb@@ -16,6 +16,7 @@ class OpenProject::XlsExport::XlsViewswhen :project_id then project_representation(value)when :user_id, :assigned_to_id then user_representation(value)when :work_package_id then work_package_representation(value)+ when :entity_gid then entity_global_id_representation(value)else superendend@@ -82,6 +83,16 @@ class OpenProject::XlsExport::XlsViewsendend+ def entity_global_id_representation(value)+ # TODO: All possible time entry associations need to be checked here+ entity = GlobalID::Locator.locate(value, only: TimeEntry::ALLOWED_ENTITY_TYPES.map(&:safe_constantize))+ if entity.is_a?(WorkPackage)+ "#{entity.type} ##{entity.id}: #{entity.subject}"+ elsif entity.is_a?(Meeting)+ "#{Meeting.model_name.human} ##{entity.id}: #{entity.title}"+ end+ end+def ar_presentation(klass, id)record = klass.find_by(id: id.to_i)