From 54ae27a41e4da3576b2ff4c604f5dad557c52d73 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 22 Jan 2018 14:11:50 +0100 Subject: [PATCH] prevent applying cost filter when money value is requested But we need to store it so that the unit is persisted. --- app/controllers/cost_reports_controller.rb | 8 ++++---- app/models/cost_query/filter/cost_type_id.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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