diff --git a/Koha/REST/V1/Transfers.pm b/Koha/REST/V1/Transfers.pm index 3061ee2c60..3e4fa492ee 100644 --- a/Koha/REST/V1/Transfers.pm +++ b/Koha/REST/V1/Transfers.pm @@ -97,7 +97,7 @@ sub cancel { # Koha::Checkin->cancel_transfer. It really belongs one level down, # in Koha::Item::Transfer->cancel, so that *every* transfer # cancellation reverts an in-transit recall regardless of the caller. - if ( C4::Context->preference('UseRecalls') ) { + if ( C4::Context->preference('UseRecalls') ne "off" ) { my $recall = Koha::Recalls->find( { item_id => $transfer->itemnumber, status => 'in_transit' } ); $recall->revert_transfer if $recall; } diff --git a/t/db_dependent/api/v1/transfers.t b/t/db_dependent/api/v1/transfers.t index 08b5cd0845..25a58cef81 100755 --- a/t/db_dependent/api/v1/transfers.t +++ b/t/db_dependent/api/v1/transfers.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Mojo; use t::lib::TestBuilder; @@ -277,3 +277,57 @@ subtest 'cancel() - UseRecalls integration' => sub { $schema->storage->txn_rollback; }; + +subtest 'cancel() - UseRecalls disabled' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'UseRecalls', 'off' ); + + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**1 } # circulate flag = 1 + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $item = $builder->build_sample_item; + my $transfer = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item->itemnumber, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + } + } + ); + + my $recall = $builder->build_object( + { + class => 'Koha::Recalls', + value => { + item_id => $item->itemnumber, + status => 'in_transit', + } + } + ); + + $t->post_ok( "//$userid:$password@/api/v1/transfers/" + . $transfer->id + . "/cancellation" => json => { cancellation_reason => 'Manual' } )->status_is(200); + + $recall->discard_changes; + is( + $recall->status, 'in_transit', + 'The in-transit recall was left untouched when UseRecalls is off' + ); + + $schema->storage->txn_rollback; +};