Skip to content

Commit

Permalink
Submit requests for bound-with children on the parent record and add …
Browse files Browse the repository at this point in the history
…a patron alert about the bound-with parent.
  • Loading branch information
cbeer committed Nov 11, 2024
1 parent fcb8393 commit 7187e85
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/jobs/submit_folio_patron_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,22 @@ def submit_folio_requests!(item_request)
def folio_request_data_for_item(request, item) # rubocop:disable Metrics/AbcSize
FolioClient::CirculationRequestData.new(
request_level: 'Item', request_type: best_request_type(request, item),
instance_id: request.instance_id, item_id: item.id, holdings_record_id: item.holdings_record_id,
instance_id: item.instance&.id || request.instance_id, item_id: item.id, holdings_record_id: item.holdings_record_id,
requester_id: request.requester_patron_id, proxy_user_id: (if request.for_sponsor?
request.patron&.id
end), fulfillment_preference: 'Hold Shelf',
pickup_service_point_id: request.pickup_service_point.id,
patron_comments: request.request_comments, request_expiration_date: (Time.zone.today + 3.years).to_time.utc.iso8601
patron_comments: patron_comments(request, item), request_expiration_date: (Time.zone.today + 3.years).to_time.utc.iso8601
)
end

def patron_comments(request, item)
[request.request_comments,
(if item.instance&.id && item.instance&.id != request.instance_id
{ bound_with_child_instance_id: request.instance_id }.to_json
end)].compact.join("\n")
end

def folio_client
@folio_client ||= FolioClient.new
end
Expand Down
22 changes: 22 additions & 0 deletions app/views/patron_requests/_confirmation_screen.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@

<hr />

<% @patron_request.selected_items.select(&:bound_with_child_holdings_record).each do |item| %>
<div class="alert alert-warning d-flex align-items-center gap-3">
<i class="bi bi-exclamation-triangle-fill me-2 text-warning fs-1"></i>

<div>
<div class="fw-bold mb-2">Important!</div>

<p>
<% if @patron_request.selected_items.one? %>
This item
<% else %>
The item <i><%= @patron_request.bib_data.title %></i> (<%= item.bound_with_child_holdings_record.call_number %>)
<% end %> is bound with other items and is shelved under the title <i><%= item.instance.title %></i> (<%= item.callnumber %>).
</p>

<p class="mb-0">
Be advised that all subsequent correspondence will reference this title. The item you requested will be included with it.
</p>
</div>
</div>
<% end %>

<h2 class="my-4">Request confirmation</h2>
<dl class="dl-inline">
<div><dt>Title:</dt><dd><%= @patron_request.item_title %></dd></div>
Expand Down
13 changes: 13 additions & 0 deletions spec/factories/folio_api_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,17 @@
]
end
end

factory :bound_with_child_holding, parent: :instance do
id { '1234' }
title { 'One bound-with child' }

holdings_records do
[
build(:holdings_record,
bound_with_item: build(:item, instance: build(:instance, title: 'Bound with parent', id: '9876'), barcode: '12345678', base_callnumber: 'ABC 123',
effective_location: build(:location, code: 'SAL3-STACKS')))
]
end
end
end
21 changes: 21 additions & 0 deletions spec/features/create_patron_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@
instance_id: bib_data.id))
end

context 'for a bound-with item' do
let(:bib_data) { build(:bound_with_child_holding) }

it 'submits the request for the bound-with parent instance' do
folio_client = FolioClient.new
allow(folio_client).to receive(:create_circulation_request)
allow(FolioClient).to receive(:new).and_return(folio_client)
allow(patron).to receive(:allowed_request_types).and_return(%w[Hold Page Recall])

visit new_patron_request_path(instance_hrid: 'a1234', origin_location_code: 'SAL3-STACKS')

perform_enqueued_jobs do
click_on 'Submit request'
expect(page).to have_content 'We received your pickup request'
expect(page).to have_content 'This item is bound with other items and is shelved under the title Bound with parent (ABC 123)'
end
expect(folio_client).to have_received(:create_circulation_request).with(have_attributes(requester_id: patron.id,
instance_id: '9876'))
end
end

context 'for a scan' do
let(:bib_data) { build(:scannable_holdings) }
let(:user) { create(:scan_eligible_user) }
Expand Down

0 comments on commit 7187e85

Please sign in to comment.