summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-12-05 10:01:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-12-05 10:01:30 +0000
commit3f44fad9bac023bee0ae023e4a0cce0aa578f0e3 (patch)
tree18f4a824cfa65024d564b4abd5faf12e1f8f8921 /app
parent55c34785c0372ee430bea835410c54e11d72bbb7 (diff)
downloadredmine-3f44fad9bac023bee0ae023e4a0cce0aa578f0e3.tar.gz
redmine-3f44fad9bac023bee0ae023e4a0cce0aa578f0e3.zip
Moved custom fields totals logic to FieldFormat (#21413).
git-svn-id: http://svn.redmine.org/redmine/trunk@14944 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/custom_field.rb4
-rw-r--r--app/models/query.rb20
2 files changed, 8 insertions, 16 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index a1373d12b..8da75031d 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -153,6 +153,10 @@ class CustomField < ActiveRecord::Base
format.query_filter_options(self, query)
end
+ def totalable?
+ format.totalable_supported
+ end
+
# Returns a ORDER BY clause that can used to sort customized
# objects by their value of the custom field.
# Returns nil if the custom field can not be used for sorting.
diff --git a/app/models/query.rb b/app/models/query.rb
index 0ba7a8c4b..ddc59f99b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -80,7 +80,7 @@ class QueryCustomFieldColumn < QueryColumn
self.name = "cf_#{custom_field.id}".to_sym
self.sortable = custom_field.order_statement || false
self.groupable = custom_field.group_statement || false
- self.totalable = ['int', 'float'].include?(custom_field.field_format)
+ self.totalable = custom_field.totalable?
@inline = true
@cf = custom_field
end
@@ -692,7 +692,7 @@ class Query < ActiveRecord::Base
end
if column.is_a?(QueryCustomFieldColumn)
custom_field = column.custom_field
- send "total_for_#{custom_field.field_format}_custom_field", custom_field, scope
+ send "total_for_custom_field", custom_field, scope
else
send "total_for_#{column.name}", scope
end
@@ -710,21 +710,9 @@ class Query < ActiveRecord::Base
group(group_by_statement)
end
- def total_for_float_custom_field(custom_field, scope)
- total_for_custom_field(custom_field, scope) {|t| t.to_f.round(2)}
- end
-
- def total_for_int_custom_field(custom_field, scope)
- total_for_custom_field(custom_field, scope) {|t| t.to_i}
- end
-
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))")
-
- total = map_total(total, &block) if block_given?
+ total = custom_field.format.total_for_scope(custom_field, scope)
+ total = map_total(total) {|t| custom_field.format.cast_total_value(custom_field, t)}
total
end