@@ -320,12 +320,12 class IssueQuery < Query | |||||
320 |
|
320 | |||
321 | # Returns sum of all the issue's estimated_hours |
|
321 | # Returns sum of all the issue's estimated_hours | |
322 | def total_for_estimated_hours(scope) |
|
322 | def total_for_estimated_hours(scope) | |
323 | scope.sum(:estimated_hours) |
|
323 | map_total(scope.sum(:estimated_hours)) {|t| t.to_f.round(2)} | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | # Returns sum of all the issue's time entries hours |
|
326 | # Returns sum of all the issue's time entries hours | |
327 | def total_for_spent_hours(scope) |
|
327 | def total_for_spent_hours(scope) | |
328 | if group_by_column.try(:name) == :project |
|
328 | total = if group_by_column.try(:name) == :project | |
329 | # TODO: remove this when https://github.com/rails/rails/issues/21922 is fixed |
|
329 | # TODO: remove this when https://github.com/rails/rails/issues/21922 is fixed | |
330 | # We have to do a custom join without the time_entries.project_id column |
|
330 | # We have to do a custom join without the time_entries.project_id column | |
331 | # that would trigger a ambiguous column name error |
|
331 | # that would trigger a ambiguous column name error | |
@@ -334,6 +334,7 class IssueQuery < Query | |||||
334 | else |
|
334 | else | |
335 | scope.joins(:time_entries).sum("#{TimeEntry.table_name}.hours") |
|
335 | scope.joins(:time_entries).sum("#{TimeEntry.table_name}.hours") | |
336 | end |
|
336 | end | |
|
337 | map_total(total) {|t| t.to_f.round(2)} | |||
337 | end |
|
338 | end | |
338 |
|
339 | |||
339 | # Returns the issues |
|
340 | # Returns the issues |
@@ -709,20 +709,22 class Query < ActiveRecord::Base | |||||
709 | total_for_custom_field(custom_field, scope) {|t| t.to_i} |
|
709 | total_for_custom_field(custom_field, scope) {|t| t.to_i} | |
710 | end |
|
710 | end | |
711 |
|
711 | |||
712 | def total_for_custom_field(custom_field, scope) |
|
712 | def total_for_custom_field(custom_field, scope, &block) | |
713 | total = scope.joins(:custom_values). |
|
713 | total = scope.joins(:custom_values). | |
714 | where(:custom_values => {:custom_field_id => custom_field.id}). |
|
714 | where(:custom_values => {:custom_field_id => custom_field.id}). | |
715 | where.not(:custom_values => {:value => ''}). |
|
715 | where.not(:custom_values => {:value => ''}). | |
716 | sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))") |
|
716 | sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))") | |
717 |
|
717 | |||
718 | if block_given? |
|
718 | total = map_total(total, &block) if block_given? | |
719 | if total.is_a?(Hash) |
|
719 | total | |
720 | total.keys.each {|k| total[k] = yield total[k]} |
|
720 | end | |
721 | else |
|
|||
722 | total = yield total |
|
|||
723 | end |
|
|||
724 | end |
|
|||
725 |
|
721 | |||
|
722 | def map_total(total, &block) | |||
|
723 | if total.is_a?(Hash) | |||
|
724 | total.keys.each {|k| total[k] = yield total[k]} | |||
|
725 | else | |||
|
726 | total = yield total | |||
|
727 | end | |||
726 | total |
|
728 | total | |
727 | end |
|
729 | end | |
728 |
|
730 |
General Comments 0
You need to be logged in to leave comments.
Login now