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

sort by date & id on time entry xls export (#8339)

ulferts7709c5b84c2d
diff --git a/modules/xls_export/lib/open_project/xls_export/xls_views/cost_entry_table.rb b/modules/xls_export/lib/open_project/xls_export/xls_views/cost_entry_table.rb
index 018447934ab..80aa133ed48 100644
--- a/modules/xls_export/lib/open_project/xls_export/xls_views/cost_entry_table.rb
+++ b/modules/xls_export/lib/open_project/xls_export/xls_views/cost_entry_table.rb
@@ -40,7 +40,7 @@ class OpenProject::XlsExport::XlsViews::CostEntryTable < OpenProject::XlsExport:
end
def build_cost_rows
- query.each_direct_result do |result|
+ sorted_results.each do |result|
spreadsheet.add_row(cost_row(result))
end
end
@@ -93,4 +93,14 @@ class OpenProject::XlsExport::XlsViews::CostEntryTable < OpenProject::XlsExport:
def cost_entry_attributes
%i[spent_on user_id activity_id work_package_id comments project_id]
end
+
+ # Returns the results of the query sorted by date the time was spent on and by id
+ def sorted_results
+ query
+ .each_direct_result
+ .map(&:itself)
+ .group_by { |r| DateTime.parse(r.fields['spent_on']) }
+ .sort
+ .flat_map { |_, date_results| date_results.sort_by { |r| r.fields['id'] } }
+ end
end