diff --git a/app/jobs/submit_folio_patron_request_job.rb b/app/jobs/submit_folio_patron_request_job.rb index 59818d8bc..cdcdc2207 100644 --- a/app/jobs/submit_folio_patron_request_job.rb +++ b/app/jobs/submit_folio_patron_request_job.rb @@ -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 diff --git a/app/views/patron_requests/_confirmation_screen.html.erb b/app/views/patron_requests/_confirmation_screen.html.erb index 574b23057..67fdf02b9 100644 --- a/app/views/patron_requests/_confirmation_screen.html.erb +++ b/app/views/patron_requests/_confirmation_screen.html.erb @@ -25,6 +25,28 @@
+ <% @patron_request.selected_items.select(&:bound_with_child_holdings_record).each do |item| %> +
+ + +
+
Important!
+ +

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

+ +

+ Be advised that all subsequent correspondence will reference this title. The item you requested will be included with it. +

+
+
+ <% end %> +

Request confirmation

Title:
<%= @patron_request.item_title %>
diff --git a/spec/factories/folio_api_json.rb b/spec/factories/folio_api_json.rb index 1048ae827..46b842680 100644 --- a/spec/factories/folio_api_json.rb +++ b/spec/factories/folio_api_json.rb @@ -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 diff --git a/spec/features/create_patron_request_spec.rb b/spec/features/create_patron_request_spec.rb index 73fed0fcd..f7d0f7542 100644 --- a/spec/features/create_patron_request_spec.rb +++ b/spec/features/create_patron_request_spec.rb @@ -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) }