From 4d58faf57456bf198e9d744eaadc9923ff8d70f6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 17 May 2021 17:14:16 +0100 Subject: [PATCH] Bug 28294: Add Koha::Item::Transfer->remedy method and use in updateWrongTransfer This patch is an interim patch to prove that the new remedy method achieves the same as updateWrongTransfer. Test plan 1/ Run t/db_dependant/Circulation.t before and after applying this patch. Signed-off-by: Victor Grousset/tuxayo --- C4/Circulation.pm | 18 ++--------------- Koha/Item/Transfer.pm | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 562cad72671..ba111a44dd6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3817,22 +3817,8 @@ This function validate the line of brachtransfer but with the wrong destination sub updateWrongTransfer { my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_; - # first step: cancel the original transfer - my $item = Koha::Items->find($itemNumber); - my $transfer = $item->get_transfer; - $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' })->store(); - - # second step: create a new transfer to the right location - my $new_transfer = $item->request_transfer( - { - to => $transfer->to_library, - reason => $transfer->reason, - comment => $transfer->comments, - ignore_limits => 1, - enqueue => 1 - } - ); - + my $transfer = Koha::Items->find($itemNumber)->get_transfer; + my $new_transfer = $transfer->remedy(); return $new_transfer; } diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm index 74ec297ec93..26d56d6171a 100644 --- a/Koha/Item/Transfer.pm +++ b/Koha/Item/Transfer.pm @@ -176,6 +176,52 @@ sub cancel { return $self; } +=head3 remedy + + my $new_transfer = $transfer->remedy( + { + to => $to_library, + reason => $reason, + [ ignore_limits => 0, force => 0 ] + } + ); + +Used when a transfer has arrived at the wrong destination. Replaces this transfer by +cancelling it with the 'WrongTransfer' reason and sets up a new transfer. + +FIXME: remedy or rectify + +=cut + +sub remedy { + my ( $self, $params ) = @_; + + # FIXME: Should we remedy a transfer if it's just gone back to the originating branch, or just leave it in transit as is. + + # Cancel the existing wrong transfer + $self->set( + { + datecancelled => dt_from_string, + cancellation_reason => 'WrongTransfer' + } + )->store(); + + # Add a new transfer and immediately set to in transit (ignoring limits) + my $new_transfer = Koha::Item::Transfer->new( + { + itemnumber => $self->itemnumber, + daterequested => dt_from_string, + datesent => undef, + frombranch => $self->item->holdingbranch, + tobranch => $self->tobranch, + reason => $self->reason, + comments => $self->comments + } + )->store(); + + return $new_transfer; +} + =head3 type =cut -- 2.43.0