prevent applying cost filter when money value is requested

But we need to store it so that the unit is persisted.
pull/6827/head
Jens Ulferts 7 years ago
parent f93e2f0d7d
commit 54ae27a41e
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 4
      app/controllers/cost_reports_controller.rb
  2. 11
      app/models/cost_query/filter/cost_type_id.rb

@ -197,11 +197,11 @@ 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
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
end
# set the @cost_types -> this is used to determine which tabs to display
def set_active_cost_types

@ -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

Loading…
Cancel
Save