@@ -, +, @@ request_transfer --- C4/Circulation.pm | 14 ++++---------- Koha/Item/Transfer.pm | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -3591,19 +3591,13 @@ 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( + my $transfer = Koha::Items->find($itemNumber)->get_transfer; + my $new_transfer = $transfer->replace( { to => $transfer->to_library, - reason => $transfer->reason, - comment => $transfer->comments, + reason => 'WrongTransfer', ignore_limits => 1, - enqueue => 1 + force => 1 } ); --- a/Koha/Item/Transfer.pm +++ a/Koha/Item/Transfer.pm @@ -186,6 +186,45 @@ sub cancel { return $self; } +=head3 replace + + my $new_transfer = $transfer->replace( + { + to => $to_library, + reason => $reason, + [ ignore_limits => 0, force => 0 ] + } + ); + +Replace this transfer by cancelling it and setting up a new transfer request. + +=cut + +sub replace { + my ( $self, $params ) = @_; + + Koha::Exceptions::MissingParameter->throw( + 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} && $in_transit ); + + my $new_transfer = $self->item->request_transfer( + { + to => $self->to_library, + reason => $params->{'reason'}, + ignore_limits => $params->{'ignore_limits'}, + force => $params->{'force'}, + replace => 1 + } + ); + + return $new_transfer; +} + =head3 type =cut --