From 1905d8b6eda2e7522c1d51305bfccb3e22964e55 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 2 Nov 2020 09:50:42 -0500 Subject: [PATCH] Bug 26896: Enable SIP option holds_block_checkin to actually block checkin of items with holds It appears that at some point, the actual blocking of checkins on items with holds got lost from the patch set. This slipped by because the sip server still outputs everything correctly, but the unit tests don't actually test to see if the checkout still exists afterward! Test plan: 1) Apply this patch 2) Prove t/db_dependent/SIP/Message.t Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- C4/SIP/ILS/Transaction/Checkin.pm | 10 +++++++--- t/db_dependent/SIP/Message.t | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index 6a38a958ac..274fda9325 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -76,7 +76,9 @@ sub do_checkin { } my ( $return, $messages, $issue, $borrower ); + my $item = Koha::Items->find( { barcode => $barcode } ); + my $human_required = 0; if ( C4::Context->preference("CircConfirmItemParts") && defined($item) @@ -86,10 +88,12 @@ sub do_checkin { $messages->{additional_materials} = 1; } + my $checkin_blocked_by_holds = $holds_block_checkin && $item->biblio->holds->count; + $debug and warn "do_checkin() calling AddReturn($barcode, $branch)"; ( $return, $messages, $issue, $borrower ) = AddReturn( $barcode, $branch, undef, $return_date ) - unless $human_required; + unless $human_required || $checkin_blocked_by_holds; if ( $checked_in_ok ) { delete $messages->{ItemLocationUpdated}; @@ -132,8 +136,8 @@ sub do_checkin { $self->{item}->destination_loc($issue->item->homebranch); $self->alert_type('04'); # send to other branch } - if ($messages->{ResFound}) { - if ($holds_block_checkin) { + if ($messages->{ResFound} || $checkin_blocked_by_holds ) { + if ($checkin_blocked_by_holds) { $self->alert_type('99'); $return = 0; } elsif ($branch eq $messages->{ResFound}->{branchcode}) { diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index 31baf30e3a..f3850f5b85 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -69,7 +69,7 @@ subtest 'Testing Patron Info Request V2' => sub { subtest 'Checkin V2' => sub { my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; - plan tests => 33; + plan tests => 35; $C4::SIP::Sip::protocol_version = 2; test_checkin_v2(); $schema->storage->txn_rollback; @@ -657,6 +657,8 @@ sub test_checkin_v2 { 'Issue record is gone now' ); # Test account option no_holds_check that prevents items on hold from being checked in via SIP + $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store; + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item is checked out"); Koha::Old::Checkouts->search({ issue_id => $issue->issue_id })->delete; $server->{account}->{holds_block_checkin} = 1; my $reserve_id = AddReserve({ @@ -673,6 +675,7 @@ sub test_checkin_v2 { is( substr($response,2,1), '0', 'OK flag is false when we check in an item on hold and we do not allow it' ); is( substr($response,5,1), 'Y', 'Alert flag is set' ); check_field( $respcode, $response, FID_SCREEN_MSG, 'Item is on hold, please return to circulation desk', 'Screen message is correct' ); + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was not checked in"); $hold->delete(); $server->{account}->{holds_block_checkin} = 0; -- 2.20.1