From d0407686eb070c5bdf0302147a198027abea5ac0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 22 Mar 2021 14:36:42 +0000 Subject: [PATCH] Bug 12362: Reverse transfer upon cancellation This patch adds a reverse transfer if a transfer is cancelled whilst it is in transit. This makes sure the item returns to it's original location. Signed-off-by: Petro Vashchuk Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Item/Transfer.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm index 96e652df28..aded4e23a5 100644 --- a/Koha/Item/Transfer.pm +++ b/Koha/Item/Transfer.pm @@ -18,6 +18,7 @@ package Koha::Item::Transfer; use Modern::Perl; use Carp; +use Try::Tiny; use C4::Items; @@ -133,14 +134,24 @@ sub cancel { error => "The 'reason' parameter is mandatory" ) unless defined($params->{reason}); + my $in_transit = $self->in_transit; + # Throw exception if item is in transit already - Koha::Exceptions::Item::Transfer::InTransit->throw() if ( !$params->{force} && $self->in_transit ); + Koha::Exceptions::Item::Transfer::InTransit->throw() if ( !$params->{force} && $in_transit ); # Update the cancelled date $self->set( { datecancelled => dt_from_string, cancellation_reason => $params->{reason} } ) ->store; + # Set up return transfer if transfer was force cancelled whilst in transit + # NOTE: We don't catch here, as we're happy to fail if there are already + # other transfers in the queue. + try { + $self->item->request_transfer( + { to => $self->frombranch, reason => 'TransferCancellation' } ); + }; + return $self; } -- 2.39.5