diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-07-13 19:02:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-07-13 19:02:48 +0000 |
commit | 793cb1676450a5b3e723a452893c10be1cb0f1bd (patch) | |
tree | 6c3922b5fed76ae41617b5ff9e215f985b0c4f9d /app/models/time_entry_query.rb | |
parent | abf3fe9c83d8e0e832d4e4d211eafbeb27ea72b1 (diff) | |
download | redmine-793cb1676450a5b3e723a452893c10be1cb0f1bd.tar.gz redmine-793cb1676450a5b3e723a452893c10be1cb0f1bd.zip |
Make time entries groupable (#16843).
git-svn-id: http://svn.redmine.org/redmine/trunk@15649 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/time_entry_query.rb')
-rw-r--r-- | app/models/time_entry_query.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index dde34264a..c667fb651 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -28,7 +28,7 @@ class TimeEntryQuery < Query QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true), QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"), QueryColumn.new(:comments), - QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours"), + QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true), ] def initialize(attributes=nil, *args) @@ -105,7 +105,7 @@ class TimeEntryQuery < Query @available_columns += TimeEntryCustomField.visible. map {|cf| QueryCustomFieldColumn.new(cf) } @available_columns += IssueCustomField.visible. - map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf) } + map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf, :totalable => false) } @available_columns end @@ -113,6 +113,14 @@ class TimeEntryQuery < Query @default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours] end + def default_totalable_names + [:hours] + end + + def base_scope + TimeEntry.visible.where(statement) + end + def results_scope(options={}) order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?) @@ -123,6 +131,11 @@ class TimeEntryQuery < Query includes(:activity). references(:activity) end + + # Returns sum of all the spent hours + def total_for_hours(scope) + map_total(scope.sum(:hours)) {|t| t.to_f.round(2)} + end def sql_for_issue_id_field(field, operator, value) case operator |