Bug 28520: Allow creating a transfer back automatically if a hold is canceled during transit

This fixes regression caused by "Bug 12362: Cancel transfer with hold
cancelation" where cancelled hold's transfer didn't show up in
intranet and opac because it create a new transfer that was not yet
put in in-transit state. The original idea of bug 12362 was to be able
to trigger transfer back home if a hold was cancelled (a regression
caused by bug 26078). However, we can do it more simply by setting the
$validTransfer variable true in the item check-in code when we are
dealing with Reserve transfers. More down in the AddReturn() code
there is also a check "and !$resfound" to make sure we only try to
trigger the transfer back home automatically if there is no hold
waiting at the current location the item arrived in.

It should be noted however that now we only display generic message
for the automatic transfer reason. Bug 12362 made the return display
as the reason "Transfer was cancelled whilst in transit". However,
since this fixes the original regressions caused by bug 26078 and
restores similar behaviour to that I think giving a more descriptive
message for example regarding a hold being cancelled can be considered
a further enhancement.

To test:
 1) Apply patch
 1) Have biblio with item in branch A
 2) Create a new hold with a pickup library to branch B
 3) Check-in the item at branch A and confirm the hold and transfer
 4) Cancel the hold
 5) Check-in the hold at branch B and notice it prompt to return it to
 branch A

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Joonas Kylmälä 2021-06-08 11:14:20 +03:00 committed by Kyle M Hall
parent c2d94e0e0d
commit bd3852bc72
2 changed files with 12 additions and 2 deletions

View File

@ -2171,6 +2171,8 @@ sub AddReturn {
if ( $transfer->tobranch eq $branch ) {
$transfer->receive;
$messages->{'TransferArrived'} = $transfer->frombranch;
# validTransfer=1 allows us returning the item back if the reserve is cancelled
$validTransfer = 1 if $transfer->reason eq 'Reserve';
}
else {
$messages->{'WrongTransfer'} = $transfer->tobranch;
@ -2182,6 +2184,8 @@ sub AddReturn {
if ( $transfer->tobranch eq $branch ) {
$transfer->receive;
$messages->{'TransferArrived'} = $transfer->frombranch;
# validTransfer=1 allows us returning the item back if the reserve is cancelled
$validTransfer = 1 if $transfer->reason eq 'Reserve';
}
else {
$messages->{'WasTransfered'} = $transfer->tobranch;

View File

@ -25,7 +25,7 @@ use Koha::CirculationRules;
use Koha::Patrons;
use Test::More tests => 15;
use Test::More tests => 16;
use t::lib::Mocks;
use t::lib::TestBuilder;
@ -307,7 +307,13 @@ is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respect
ModItemTransfer($item_id2, $samplebranch2->{branchcode}, $samplebranch1->{branchcode}, "ReturnToHolding");
# Fulfill it
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2',$samplebranch1->{branchcode});
is( $messages->{NeedsTransfer}, undef, "AddReturn does not generate a new transfer for return policy when resolving an existing transfer" );
is( $messages->{NeedsTransfer}, undef, "AddReturn does not generate a new transfer for return policy when resolving an existing non-Reserve transfer" );
# Generate a hold caused transfer which doesn't have a hold i.e. is the hold is cancelled
ModItemTransfer($item_id2, $samplebranch2->{branchcode}, $samplebranch1->{branchcode}, "Reserve");
# Fulfill it
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2',$samplebranch1->{branchcode});
is( $messages->{NeedsTransfer}, $samplebranch2->{branchcode}, "AddReturn generates a new transfer for hold transfer if the hold was cancelled" );
# item3 should not trigger transfer - floating collection
$query =