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

pull/8351/head
ulferts 5 years ago committed by GitHub
parent e9371af978
commit 7709c5b84c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      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 end
def build_cost_rows def build_cost_rows
query.each_direct_result do |result| sorted_results.each do |result|
spreadsheet.add_row(cost_row(result)) spreadsheet.add_row(cost_row(result))
end end
end end
@ -93,4 +93,14 @@ class OpenProject::XlsExport::XlsViews::CostEntryTable < OpenProject::XlsExport:
def cost_entry_attributes def cost_entry_attributes
%i[spent_on user_id activity_id work_package_id comments project_id] %i[spent_on user_id activity_id work_package_id comments project_id]
end 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 end

Loading…
Cancel
Save