From 6b9b7d8e779b29ec5bb9ec2a2e84c91eb1c5b19e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 14 Dec 2020 15:54:54 +0100 Subject: [PATCH] Bug 27196: Don't explode if item that is waiting if checked in by SIP Signed-off-by: Nick Clemens Signed-off-by: Victor Grousset/tuxayo Signed-off-by: David Cook Signed-off-by: Jonathan Druart --- C4/SIP/ILS/Transaction/Checkin.pm | 6 ++--- t/db_dependent/SIP/Transaction.t | 40 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index 1b82a7138b..f674314e12 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -1,4 +1,4 @@ -# + # An object to handle checkin status # @@ -149,9 +149,9 @@ sub do_checkin { } else { $self->hold($messages->{ResFound}); $self->alert_type('02'); - ModReserveAffect( $messages->{ResFound}->{itemnumber}, + ModReserveAffect( $item->itemnumber, $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id}); - ModItemTransfer( $messages->{ResFound}->{itemnumber}, + ModItemTransfer( $item->itemnumber, $branch, $messages->{ResFound}->{branchcode}, $messages->{TransferTrigger}, diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index d9cbf35490..ee29265998 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -272,7 +272,7 @@ subtest do_hold => sub { }; subtest do_checkin => sub { - plan tests => 11; + plan tests => 12; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); @@ -327,6 +327,44 @@ subtest do_checkin => sub { is_deeply($result,{ messages => { 'NotIssued' => $item->barcode, 'WasTransfered' => 1 } },"Messages show not issued and transferred"); is( $ci_transaction->item->destination_loc,$library->branchcode,"Item destination correctly set"); + subtest 'Checkin an in transit item' => sub { + + plan tests => 5; + + my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); + my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); + + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $library_1->branchcode, }}); + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $item = $builder->build_sample_item({ library => $library_1->branchcode }); + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); + + t::lib::Mocks::mock_userenv( + { branchcode => $library_1->branchcode, flags => 1 } ); + + my $reserve = AddReserve( + { + branchcode => $library_1->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblionumber, + } + ); + + ModReserveAffect( $item->itemnumber, $patron->borrowernumber ); # Mark waiting + + my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new(); + is( $ci_transaction->patron($sip_patron), + $sip_patron, "Patron assigned to transaction" ); + is( $ci_transaction->item($sip_item), + $sip_item, "Item assigned to transaction" ); + + my $checkin = $ci_transaction->do_checkin($library_2->branchcode, C4::SIP::Sip::timestamp); + + my $hold = Koha::Holds->find($reserve); + is( $hold->found, 'T', ); + is( $hold->itemnumber, $item->itemnumber, ); + is( Koha::Checkouts->search({itemnumber => $item->itemnumber})->count, 0, ); + }; }; subtest checkin_lost => sub { -- 2.39.5