Skip to content

Commit

Permalink
Remove order by from model scope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjlynch committed Oct 10, 2024
1 parent 8dc06dd commit 94aebf2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/payroll_runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/forms/admin/claims_filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 94aebf2

Please sign in to comment.