]> source.dussan.org Git - redmine.git/commitdiff
Fixes float conversion failures (#1561).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 12:44:08 +0000 (12:44 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 12:44:08 +0000 (12:44 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14668 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb
app/models/query.rb

index 4528f4a9bef6168930ad693b24181adda9cd205a..37f7ee39151fcf344cbed549a0658bb58fa6bb6c 100644 (file)
@@ -320,12 +320,12 @@ class IssueQuery < Query
 
   # Returns sum of all the issue's estimated_hours
   def total_for_estimated_hours(scope)
-    scope.sum(:estimated_hours)
+    map_total(scope.sum(:estimated_hours)) {|t| t.to_f.round(2)}
   end
 
   # Returns sum of all the issue's time entries hours
   def total_for_spent_hours(scope)
-    if group_by_column.try(:name) == :project
+    total = if group_by_column.try(:name) == :project
       # TODO: remove this when https://github.com/rails/rails/issues/21922 is fixed
       # We have to do a custom join without the time_entries.project_id column
       # that would trigger a ambiguous column name error
@@ -334,6 +334,7 @@ class IssueQuery < Query
     else
       scope.joins(:time_entries).sum("#{TimeEntry.table_name}.hours")
     end
+    map_total(total) {|t| t.to_f.round(2)}
   end
 
   # Returns the issues
index 452b6d00c7a8819a97ed183597ac9d8eaa2f58f0..fbcf2e6465b5c31bd21312ddd69066764303334f 100644 (file)
@@ -709,20 +709,22 @@ class Query < ActiveRecord::Base
     total_for_custom_field(custom_field, scope) {|t| t.to_i}
   end
 
-  def total_for_custom_field(custom_field, scope)
+  def total_for_custom_field(custom_field, scope, &block)
     total = scope.joins(:custom_values).
       where(:custom_values => {:custom_field_id => custom_field.id}).
       where.not(:custom_values => {:value => ''}).
       sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))")
 
-    if block_given?
-      if total.is_a?(Hash)
-        total.keys.each {|k| total[k] = yield total[k]}
-      else
-        total = yield total
-      end
-    end
+    total = map_total(total, &block) if block_given?
+    total
+  end
 
+  def map_total(total, &block)
+    if total.is_a?(Hash)
+      total.keys.each {|k| total[k] = yield total[k]}
+    else
+      total = yield total
+    end
     total
   end