Skip to content

Commit

Permalink
Merge pull request #1104 from sul-dlss/1083-check-for-holds
Browse files Browse the repository at this point in the history
Check whether a hold is present that blocks renewal
  • Loading branch information
jcoyne authored Jun 12, 2024
2 parents f469d61 + 095fb87 commit 44f6927
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 26 deletions.
10 changes: 8 additions & 2 deletions app/models/folio/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Checkout

delegate :loan_policy_interval,
:too_soon_to_renew?,
:renewal_blocked_by_hold?,
:unseen_renewals_remaining,
:seen_renewals_remaining,
to: :loan_policy,
Expand Down Expand Up @@ -60,7 +61,7 @@ def claimed_returned?
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
def non_renewable_reason
return 'Item is assumed lost; you must pay the fee or return the item.' if lost?
return 'No. Another user is waiting for this item.' if recalled?
return 'No. Another user is waiting for this item.' if recalled? || renewal_blocked_by_hold?
return 'No. Claim review is in process.' if claimed_returned?

unless unseen_renewals_remaining.positive?
Expand Down Expand Up @@ -169,7 +170,8 @@ def barcode
def loan_policy
@loan_policy ||= Folio::LoanPolicy.new(loan_policy: effective_loan_policy,
due_date:,
renewal_count:)
renewal_count:,
hold_queue_length:)
end

def effective_loan_policy
Expand Down Expand Up @@ -211,5 +213,9 @@ def reserve_item?
def renewal_count
record.dig('details', 'renewalCount') || 0
end

def hold_queue_length
record.dig('item', 'item', 'queueTotalLength') || 0
end
end
end
15 changes: 12 additions & 3 deletions app/models/folio/loan_policy.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

module Folio
class LoanPolicy
attr_reader :loan_policy, :due_date, :renewal_count
class LoanPolicy # rubocop:disable Metrics/ClassLength
attr_reader :loan_policy, :due_date, :renewal_count, :hold_queue_length

def initialize(loan_policy:, due_date:, renewal_count:)
def initialize(loan_policy:, due_date:, renewal_count:, hold_queue_length:)
@loan_policy = loan_policy
@due_date = due_date
@renewal_count = renewal_count
@hold_queue_length = hold_queue_length
end

def loan_policy_interval
Expand Down Expand Up @@ -39,6 +40,10 @@ def description
loan_policy['description']
end

def renewal_blocked_by_hold?
hold_queue_length.positive? && !renewals_allowed_with_open_holds?
end

private

def due_date_after_renewal
Expand Down Expand Up @@ -131,5 +136,9 @@ def unlimited_renewals?
def unseen_renewals_allowed
loan_policy.dig('renewalsPolicy', 'numberAllowed') || 0
end

def renewals_allowed_with_open_holds?
loan_policy.dig('requestManagement', 'holds', 'renewItemsWithRequest') || false
end
end
end
6 changes: 6 additions & 0 deletions app/services/folio_graphql_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def loan_policies
}
}
}
requestManagement {
holds {
renewItemsWithRequest
}
}
}
}"
})
Expand Down Expand Up @@ -332,6 +337,7 @@ def patron_info(patron_uuid)
code
}
}
queueTotalLength
}
}
loanDate
Expand Down
Loading

0 comments on commit 44f6927

Please sign in to comment.