diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index 346578e3ce..0c987ffd89 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -197,10 +197,10 @@ class CostReportsController < ApplicationController # Determine the active cost type, if it is not labor or money, and add a hidden filter to the query # sets the @cost_type -> this is used to select the proper units for display def set_cost_type - if @query - @query.filter :cost_type_id, operator: '=', value: @unit_id.to_s, display: false - @cost_type = CostType.find(@unit_id) if @unit_id > 0 - end + return unless @query + + @query.filter :cost_type_id, operator: '=', value: @unit_id.to_s, display: false + @cost_type = CostType.find(@unit_id) if @unit_id > 0 end # set the @cost_types -> this is used to determine which tabs to display diff --git a/app/models/cost_query/filter/cost_type_id.rb b/app/models/cost_query/filter/cost_type_id.rb index b212a4d59d..3998bda296 100644 --- a/app/models/cost_query/filter/cost_type_id.rb +++ b/app/models/cost_query/filter/cost_type_id.rb @@ -38,6 +38,17 @@ class CostQuery::Filter::CostTypeId < Report::Filter::Base @display end + def field + # prevent setting an extra cost type constraint + # WHERE cost_type_id IN (...) + # when money value is requested + if values == ["0"] + [] + else + super + end + end + def self.available_values(*) [[::I18n.t(:caption_labor), -1]] + CostType.order('name').pluck(:name, :id) end