Migrate further AR finders with conditions

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/6827/head
Alex Coles 9 years ago
parent e3ab9d678a
commit 3e5f5a17fd
  1. 10
      app/controllers/hourly_rates_controller.rb
  2. 2
      app/models/rate_observer.rb
  3. 2
      lib/open_project/costs/patches/projects_controller_patch.rb
  4. 4
      lib/open_project/costs/patches/query_patch.rb
  5. 2
      lib/open_project/costs/patches/time_entry_patch.rb

@ -37,9 +37,8 @@ class HourlyRatesController < ApplicationController
if @project
return deny_access unless User.current.allowed_to?(:view_hourly_rates, @project, for: @user)
@rates = HourlyRate.all(
conditions: { user_id: @user, project_id: @project },
order: "#{HourlyRate.table_name}.valid_from desc")
@rates = HourlyRate.where(user_id: @user, project_id: @project)
.order("#{HourlyRate.table_name}.valid_from desc")
else
@rates = HourlyRate.history_for_user(@user, true)
@rates_default = @rates.delete(nil)
@ -58,9 +57,8 @@ class HourlyRatesController < ApplicationController
end
if @project.nil?
@rates = DefaultHourlyRate.all(
conditions: { user_id: @user },
order: "#{DefaultHourlyRate.table_name}.valid_from desc")
@rates = DefaultHourlyRate.where(user_id: @user)
.order("#{DefaultHourlyRate.table_name}.valid_from desc")
@rates << @user.default_rates.build(valid_from: Date.today) if @rates.empty?
else
@rates = @user.rates.select { |r| r.project_id == @project.id }.sort { |a, b| b.valid_from <=> a.valid_from }

@ -84,7 +84,7 @@ class RateObserver < ActiveRecord::Observer
end
def count_rates(date1, date2 = nil)
(@rate.class).count(conditions: conditions_between(date1, date2, :valid_from))
(@rate.class).where(conditions_between(date1, date2, :valid_from)).count
end
def orphaned_child_entries(date1, date2 = nil)

@ -30,7 +30,7 @@ module OpenProject::Costs::Patches::ProjectsControllerPatch
def own_total_hours
if User.current.allowed_to?(:view_own_time_entries, @project)
cond = @project.project_condition(Setting.display_subprojects_work_packages?)
@total_hours = TimeEntry.visible.sum(:hours, include: :project, conditions: cond).to_f
@total_hours = TimeEntry.visible.includes(:project).where(cond).sum(:hours).to_f
end
end
end

@ -79,7 +79,9 @@ module OpenProject::Costs::Patches::QueryPatch
'cost_object_id' => {
type: :list_optional,
order: 14,
values: CostObject.all(conditions: ['project_id IN (?)', project], order: 'subject ASC').map { |d| [d.subject, d.id.to_s] }
values: CostObject.where(project_id: project)
.order('subject ASC')
.map { |d| [d.subject, d.id.to_s] }
},
}
else

@ -62,7 +62,7 @@ module OpenProject::Costs::Patches::TimeEntryPatch
# to trigger the update of the costs based on new rates
if conditions.respond_to?(:keys) && conditions.keys == [:work_package_id] && updates =~ /^project_id = ([\d]+)$/
project_id = $1
time_entries = TimeEntry.all(conditions: conditions)
time_entries = TimeEntry.where(conditions)
time_entries.each do |entry|
entry.project_id = project_id
entry.save!

Loading…
Cancel
Save