From 95edc4314b848ee7819aa4f5541586e5a57b0f41 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 10 Feb 2020 18:18:45 +0000 Subject: [PATCH] Bug 24620: [19.11.x] Close existing transfer when hold set to waiting (squashed) Signed-off-by: Jonathan Druart Bug 24620: Close existing transfers when setting item to waiting This patch adds a clause in ModReserveAffect to check if there are existing transfers and close them when setting a hold to waiting To test: 1 - Set AutomaticItemReturn to Do 2 - Checkin an item from Library B at Library A 3 - Confirm item is in transfer (check the details page) 4 - Place a item level hold for pickup at library A 5 - Checkin the item at Library A 6 - Confirm the hold 7 - View the details page 8 - Note the item is in transit and waiting 9 - Apply patch 10 - Delete hold and repeat 11 - Confirm that transfer is closed when hold marked waiting Signed-off-by: Sally Signed-off-by: Stina Hallin Signed-off-by: Jonathan Druart Bug 24620: Fix test, remove replaced code, use dt_from_string Signed-off-by: Jonathan Druart --- C4/Reserves.pm | 13 +++++++++++-- t/db_dependent/Circulation.t | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 86b4b8ba2c..cc4bc5e9b4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1105,8 +1105,17 @@ sub ModReserveAffect { $hold->itemnumber($itemnumber); $hold->set_waiting($transferToDo); - _koha_notify_reserve( $hold->reserve_id ) - if ( !$transferToDo && !$already_on_shelf ); + if( !$transferToDo ){ + _koha_notify_reserve( $hold->reserve_id ) unless $already_on_shelf; + my $transfers = Koha::Item::Transfers->search({ + itemnumber => $itemnumber, + datearrived => undef + }); + while( my $transfer = $transfers->next ){ + $transfer->datearrived( dt_from_string() )->store; + }; + } + _FixPriority( { biblionumber => $biblionumber } ); my $item = Koha::Items->find($itemnumber); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 2c3d3aa2b4..3514dc8553 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 46; +use Test::More tests => 47; use Test::MockModule; use Data::Dumper; @@ -40,8 +40,10 @@ use Koha::DateUtils; use Koha::Database; use Koha::IssuingRules; use Koha::Items; +use Koha::Item::Transfers; use Koha::Checkouts; use Koha::Patrons; +use Koha::Holds; use Koha::CirculationRules; use Koha::Subscriptions; use Koha::Account::Lines; @@ -3424,6 +3426,40 @@ subtest "Test Backdating of Returns" => sub { is( $accountline->amount+0, 0, 'Fee amount was reduced to 0' ); }; +subtest 'Filling a hold should cancel existing transfer' => sub { + plan tests => 4; + + t::lib::Mocks::mock_preference('AutomaticItemReturn', 1); + + my $libraryA = $builder->build_object( { class => 'Koha::Libraries' } ); + my $libraryB = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $patron_category->{categorycode}, + branchcode => $libraryA->branchcode, + } + } + )->store; + + my $item = $builder->build_sample_item({ + homebranch => $libraryB->branchcode, + }); + + my ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef ); + is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 1, "We generate a transfer on checkin"); + AddReserve($libraryA->branchcode,$patron->borrowernumber,$item->biblionumber,undef,undef,undef,undef,undef,undef,$item->itemnumber); + my $reserves = Koha::Holds->search({ itemnumber => $item->itemnumber }); + is( $reserves->count, 1, "Reserve is placed"); + ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef ); + my $reserve = $reserves->next; + ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve->reserve_id ); + $reserve->discard_changes; + ok( $reserve->found eq 'W', "Reserve is marked waiting" ); + is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting"); +}; + $schema->storage->txn_rollback; C4::Context->clear_syspref_cache(); $cache->clear_from_cache('single_holidays'); -- 2.11.0