Bug 24620: [19.11.x] Close existing transfer when hold set to waiting (squashed)

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

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 <sally.healey@cheshirewestandchester.gov.uk>

Signed-off-by: Stina Hallin <stina.hallin@ub.lu.se>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Bug 24620: Fix test, remove replaced code, use dt_from_string

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2020-02-10 18:18:45 +00:00 committed by Joy Nelson
parent 8ed0d57c95
commit 88526da244
2 changed files with 48 additions and 3 deletions

View File

@ -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);

View File

@ -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');