From 256ae4dd5c1aeec90bce7c2580e35075d996d1a7 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Thu, 10 Oct 2024 14:34:32 +0100 Subject: [PATCH] Remove order by from model scope We move the order clause to where it's needed rather than having it on every call to `payrollable`, this lets us simplify the distinct clause as we no longer need to include the `submitted_at` in the distinct. --- app/controllers/admin/payroll_runs_controller.rb | 2 +- app/forms/admin/claims_filter_form.rb | 2 +- app/models/claim.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/payroll_runs_controller.rb b/app/controllers/admin/payroll_runs_controller.rb index 1604cd1a3a..d1feac8886 100644 --- a/app/controllers/admin/payroll_runs_controller.rb +++ b/app/controllers/admin/payroll_runs_controller.rb @@ -9,7 +9,7 @@ def index end def new - @claims = Claim.payrollable + @claims = Claim.payrollable.order(submitted_at: :asc) # Due to limitations with the current payroll software we need a temporary # cap on the number of claims that can enter payroll, especially expecting diff --git a/app/forms/admin/claims_filter_form.rb b/app/forms/admin/claims_filter_form.rb index 35ac401989..650ff6eed7 100644 --- a/app/forms/admin/claims_filter_form.rb +++ b/app/forms/admin/claims_filter_form.rb @@ -68,7 +68,7 @@ def claims @claims = @claims.includes(:tasks, eligibility: [:claim_school, :current_school]) - @claims = @claims.select("DISTINCT ON (claims.id, claims.submitted_at) claims.id") + @claims = @claims.select("DISTINCT ON (claims.id) claims.id") @claims = Claim.where(id: @claims) diff --git a/app/models/claim.rb b/app/models/claim.rb index ba0c5d1e9d..9006adb23c 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -205,7 +205,7 @@ class Claim < ApplicationRecord delegate :award_amount, to: :eligibility - scope :payrollable, -> { approved.not_awaiting_qa.left_joins(:payments).where(payments: nil).order(submitted_at: :asc) } + scope :payrollable, -> { approved.not_awaiting_qa.left_joins(:payments).where(payments: nil) } scope :not_awaiting_qa, -> { approved.where("qa_required = false OR (qa_required = true AND qa_completed_at IS NOT NULL)") } scope :awaiting_qa, -> { approved.qa_required.where(qa_completed_at: nil) } scope :qa_required, -> { where(qa_required: true) }