From 870d8beb70530f3f9036f7564d97b46016448298 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 29 Jun 2023 08:06:51 -0400 Subject: [PATCH] Bug 34153: Add ability to allow items with additional materials notes to be checked out via SIP At this time, any item with an additional materials date is blocked from checkout via SIP with a screen message to take the item to a circulation desk for checkout. Some libraries wish to allow patrons to check out items via SIP even if the item has additional materials. Test Plan: 1) Create an item with an additional materials note 2) Attempt to check it out via SIP 3) Note the failure and message 4) Enable the new SIP account option "allow_additional_materials_checkout" 5) Restart the SIP server 6) Attempt the checkout again 7) Note the checkout success and new AF field message! 8) prove t/db_dependent/SIP/Message.t Signed-off-by: David Nind --- C4/SIP/ILS/Transaction/Checkout.pm | 13 ++++-- etc/SIPconfig.xml | 1 + t/db_dependent/SIP/Message.t | 68 +++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index d9056f1c82..f8ca614b42 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -18,6 +18,7 @@ use C4::Context; use C4::Circulation qw( AddIssue GetIssuingCharges CanBookBeIssued ProcessOfflineIssue ); use C4::Members; use Koha::DateUtils qw( dt_from_string ); +use Koha::Items; use parent qw(C4::SIP::ILS::Transaction); @@ -48,6 +49,7 @@ sub do_checkout { my $patron = Koha::Patrons->find($self->{patron}->{borrowernumber}); my $overridden_duedate; # usually passed as undef to AddIssue my $prevcheckout_block_checkout = $account->{prevcheckout_block_checkout}; + my $allow_additional_materials_checkout = $account->{allow_additional_materials_checkout}; my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode, 0); if ( $no_block_due_date ) { @@ -105,9 +107,14 @@ sub do_checkout { $noerror = 0 if ($prevcheckout_block_checkout); last; } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) { - $self->screen_msg('Item must be checked out at a circulation desk'); - $noerror = 0; - last; + if ( $allow_additional_materials_checkout ) { + my $item = Koha::Items->find({ barcode => $barcode }); + $self->screen_msg( 'Item has additional materials: ' . $item->materials ); + } else { + $self->screen_msg('Item must be checked out at a circulation desk'); + $noerror = 0; + last; + } } else { # We've been returned a case other than those above $self->screen_msg("Item cannot be issued: $confirmation"); diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index 5264c2674c..36604a04a2 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -69,6 +69,7 @@ da_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]" av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]" hide_fields="BD,BE,BF,PB" + allow_additional_materials_checkout="1" register_id='' holds_block_checkin="0" holds_get_captured="1" diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index e4f0e38385..1148b8d154 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use Test::Exception; use Test::MockObject; use Test::MockModule; @@ -577,6 +577,72 @@ subtest 'SC status tests' => sub { }; +subtest 'test_allow_additional_materials_checkout' => sub { + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 4; + + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + + # create some data + my $patron1 = $builder->build({ + source => 'Borrower', + value => { + password => hash_password( PATRON_PW ), + }, + }); + my $card1 = $patron1->{cardnumber}; + my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); + $findpatron = $sip_patron1; + my $item_object = $builder->build_sample_item({ + damaged => 0, + withdrawn => 0, + itemlost => 0, + restricted => 0, + homebranch => $branchcode, + holdingbranch => $branchcode, + materials => "This is a materials note", + }); + + my $mockILS = $mocks->{ils}; + my $server = { ils => $mockILS, account => {} }; + $mockILS->mock( 'institution', sub { $branchcode; } ); + $mockILS->mock( 'supports', sub { return; } ); + $mockILS->mock( 'checkout', sub { + shift; + return C4::SIP::ILS->checkout(@_); + }); + my $today = dt_from_string; + t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); + t::lib::Mocks::mock_preference( 'CircConfirmItemParts', '1' ); + + my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . + siprequestdate( $today->clone->add( days => 1) ) . + FID_INST_ID . $branchcode . '|'. + FID_PATRON_ID . $sip_patron1->id . '|' . + FID_ITEM_ID . $item_object->barcode . '|' . + FID_TERMINAL_PWD . 'ignored' . '|'; + undef $response; + + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + $server->{account}->{allow_additional_materials_checkout} = 0; + $msg->handle_checkout( $server ); + my $respcode = substr( $response, 0, 2 ); + check_field( $respcode, $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk', 'Check screen msg', 'equals' ); + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (allow_additional_materials_checkout disabled)"); + + $server->{account}->{allow_additional_materials_checkout} = 1; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 0, 2 ); + check_field( $respcode, $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note', 'Check screen msg', 'equals' ); + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (allow_additional_materials_checkout enabled"); +}; + # Here is room for some more subtests # END of main code -- 2.30.2