Class: Redmine::FieldFormat::Numeric

Inherits:
Unbounded show all
Defined in:
lib/redmine/field_format.rb

Overview

Since:

  • 2.5.0

Direct Known Subclasses

FloatFormat, IntFormat

Instance Method Summary collapse

Methods inherited from Unbounded

#validate_single_value

Methods inherited from Base

#after_save_custom_value, #before_custom_field_save, #bulk_edit_tag, #cast_custom_value, #cast_single_value, #cast_value, #edit_tag, field_attributes, #formatted_custom_value, #formatted_value, #group_statement, #join_for_order_statement, #label, #name, #possible_custom_value_options, #possible_values_options, #query_filter_options, #set_custom_field_value, #target_class, #validate_custom_field, #validate_custom_value, #validate_single_value, #value_from_keyword

Methods included from Helpers::URL

#uri_with_safe_scheme?

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#cast_total_value(custom_field, value) ⇒ Object

Since:

  • 3.2.0



471
472
473
# File 'lib/redmine/field_format.rb', line 471

def cast_total_value(custom_field, value)
  cast_single_value(custom_field, value)
end

#order_statement(custom_field) ⇒ Object



456
457
458
459
460
461
# File 'lib/redmine/field_format.rb', line 456

def order_statement(custom_field)
  # Make the database cast values into numeric
  # Postgresql will raise an error if a value can not be casted!
  # CustomValue validations should ensure that it doesn't occur
  "CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))"
end

#total_for_scope(custom_field, scope) ⇒ Object

Returns totals for the given scope

Since:

  • 3.2.0



464
465
466
467
468
469
# File 'lib/redmine/field_format.rb', line 464

def total_for_scope(custom_field, scope)
  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))")
end