diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index fb26c3a36a..0798562811 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -160,7 +160,7 @@ class CostReportsController < ApplicationController # set the @cost_types -> this is used to determine which tabs to display def set_active_cost_types unless session[:report] && (@cost_types = session[:report][:filters][:values][:cost_type_id].try(:collect, &:to_i)) - relevant_cost_types = CostType.find(:all, select: 'id', order: 'id ASC').select do |t| + relevant_cost_types = CostType.select(:id).order('id ASC').select do |t| t.cost_entries.count > 0 end.collect(&:id) @cost_types = [-1, 0, *relevant_cost_types] @@ -222,29 +222,24 @@ class CostReportsController < ApplicationController def public_queries if @project - CostQuery.find(:all, - conditions: ['is_public = ? AND (project_id IS NULL OR project_id = ?)', - true, @project], - order: 'name ASC') + CostQuery.where(['is_public = ? AND (project_id IS NULL OR project_id = ?)', true, @project]) + .order('name ASC') else - CostQuery.find(:all, - conditions: ['is_public = ? AND project_id IS NULL', - true], - order: 'name ASC') + CostQuery.where(['is_public = ? AND project_id IS NULL', true]) + .order('name ASC') end end def private_queries if @project - CostQuery.find(:all, - conditions: ['user_id = ? AND is_public = ? AND (project_id IS NULL OR project_id = ?)', - current_user, false, @project], - order: 'name ASC') + CostQuery.where(['user_id = ? AND is_public = ? AND (project_id IS NULL OR project_id = ?)', + current_user, + false, + @project]) + .order('name ASC') else - CostQuery.find(:all, - conditions: ['user_id = ? AND is_public = ? AND project_id IS NULL', - current_user, false], - order: 'name ASC') + CostQuery.where(['user_id = ? AND is_public = ? AND project_id IS NULL', current_user, false]) + .order('name ASC') end end diff --git a/app/models/cost_query/filter/activity_id.rb b/app/models/cost_query/filter/activity_id.rb index 4e52025755..9d4bc17f66 100644 --- a/app/models/cost_query/filter/activity_id.rb +++ b/app/models/cost_query/filter/activity_id.rb @@ -23,6 +23,6 @@ class CostQuery::Filter::ActivityId < Report::Filter::Base end def self.available_values(*) - TimeEntryActivity.find(:all, order: 'name').map { |a| [a.name, a.id] } + TimeEntryActivity.order('name').pluck(:name, :id) end end diff --git a/app/models/cost_query/filter/cost_object_id.rb b/app/models/cost_query/filter/cost_object_id.rb index 3c8303cb39..328ea5b2ce 100644 --- a/app/models/cost_query/filter/cost_object_id.rb +++ b/app/models/cost_query/filter/cost_object_id.rb @@ -26,6 +26,6 @@ class CostQuery::Filter::CostObjectId < Report::Filter::Base end def self.available_values(*) - ([[l(:caption_labor), -1]] + CostObject.find(:all, order: 'name').map { |t| [t.name, t.id] }) + [[l(:caption_labor), -1]] + CostObject.order('name').pluck(:name, :id) end end diff --git a/app/models/cost_query/filter/cost_type_id.rb b/app/models/cost_query/filter/cost_type_id.rb index 987cef14a6..b212a4d59d 100644 --- a/app/models/cost_query/filter/cost_type_id.rb +++ b/app/models/cost_query/filter/cost_type_id.rb @@ -39,6 +39,6 @@ class CostQuery::Filter::CostTypeId < Report::Filter::Base end def self.available_values(*) - ([[::I18n.t(:caption_labor), -1]] + CostType.find(:all, order: 'name').map { |t| [t.name, t.id] }) + [[::I18n.t(:caption_labor), -1]] + CostType.order('name').pluck(:name, :id) end end diff --git a/app/models/cost_query/filter/priority_id.rb b/app/models/cost_query/filter/priority_id.rb index 8be084f152..7484d6c490 100644 --- a/app/models/cost_query/filter/priority_id.rb +++ b/app/models/cost_query/filter/priority_id.rb @@ -26,6 +26,6 @@ class CostQuery::Filter::PriorityId < Report::Filter::Base end def self.available_values(*) - IssuePriority.find(:all, order: 'position DESC').map { |i| [i.name, i.id] } + IssuePriority.order('position DESC').pluck(:name, :id) end end diff --git a/app/models/cost_query/filter/status_id.rb b/app/models/cost_query/filter/status_id.rb index b679edf948..1c5f611b43 100644 --- a/app/models/cost_query/filter/status_id.rb +++ b/app/models/cost_query/filter/status_id.rb @@ -29,6 +29,6 @@ class CostQuery::Filter::StatusId < Report::Filter::Base end def self.available_values(*) - Status.find(:all, order: 'name').map { |i| [i.name, i.id] } + Status.order('name').pluck(:name, :id) end end diff --git a/app/models/cost_query/filter/type_id.rb b/app/models/cost_query/filter/type_id.rb index 885d1a6fa7..423ca58b95 100644 --- a/app/models/cost_query/filter/type_id.rb +++ b/app/models/cost_query/filter/type_id.rb @@ -26,6 +26,6 @@ class CostQuery::Filter::TypeId < Report::Filter::Base end def self.available_values(*) - Type.find(:all, order: 'name').map { |i| [i.name, i.id] } + Type.order('name').pluck(:name, :id) end end