Bug 12362: Cancel transfer with hold cancelation

This patch adds a transfer cancellation when a hold is cancelled.

Test plan
1/ Check an item out from it's homebranch
2/ Place a hold on that item for another user at a different branch
3/ Check the item in at it's homebranch and accept the transfer
4/ Cancel the hold
5/ Change to the second branch and check the item in
6/ Note that a transfer is triggered with the reason 'Transfer was
cancelled whilst in transit'

Signed-off-by: Petro Vashchuk <stalkernoid@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

JD amended patch: remove trailing whitespace

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2021-03-22 14:57:06 +00:00 committed by Jonathan Druart
parent d0407686eb
commit 6c10582914
3 changed files with 31 additions and 4 deletions

View file

@ -497,8 +497,17 @@ Cancel a hold:
sub cancel {
my ( $self, $params ) = @_;
$self->_result->result_source->schema->txn_do(
sub {
if ( $self->is_in_transit ) {
my $transfer = $self->item->get_transfer;
# NOTE: Transfers are well bound with Holds.. as such we have to check that there is actually a
# transfer enqueued and in transit here prior to trying to cancel it.
if ( $transfer && $transfer->in_transit ) {
$transfer->cancel({ reason => 'CancelReserve', force => 1 });
}
}
$self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
$self->priority(0);
$self->cancellation_reason( $params->{cancellation_reason} );

View file

@ -52,6 +52,20 @@ sub item {
return Koha::Item->_new_from_dbic($item_rs);
}
=head3 from_library
my $from_library = $transfer->from_library;
Returns the associated from_library for this transfer.
=cut
sub from_library {
my ($self) = @_;
my $from_library_rs = $self->_result->frombranch;
return Koha::Library->_new_from_dbic($from_library_rs);
}
=head3 transit
Set the transfer as in transit by updating the datesent time.
@ -147,10 +161,12 @@ sub cancel {
# 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' } );
};
if ($in_transit) {
try {
$self->item->request_transfer(
{ to => $self->from_library, reason => 'TransferCancellation' } );
};
}
return $self;
}

View file

@ -134,6 +134,8 @@
[%- CASE 'Reserve' -%]Reserve
[%- CASE 'LostReserve' -%]Lost reserve
[%- CASE 'CancelReserve' -%]Cancelled reserve
[%- CASE 'TransferCancellation' -%]Transfer was cancelled whilst in transit
[%- CASE -%][% trigger | html %]
[%- END -%]
</p>
</div>