From 7a1ef5af66e243dc5d7caa9d416426affa94149e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 6 May 2021 13:53:51 +0100 Subject: [PATCH] Bug 24434: Reinstate updateWrongTransfer This patch re-instates the call to updateWrongTransfer to ensure the transfer line it updated to reflect the new frombranch. Test plan 1/ Check an item out from it's home library 2/ Check the item in at another library (with the return to home branch system preferences enabled) 2a/ Accept the transfer and note we now have a transfer present from the items check-in library to it's home library 3/ Check the item in at a third library 3a/ Note you are asked to return the item to it's home library. 3b/ With the patch applied, the modal title should highlight that a 'Wrong transfer' was detected. 4/ Go to the item record and note the holding library has been updated to reflect where the item was most recently checked in. 4a/ With the patch applied the item status should reflect the last checked in branch as the 'from' branch of the transfer. 5/ Work through the above again, but use the 'Print slip' option for accepting the transfer and confirm that also works. --- C4/Circulation.pm | 32 +++++++++++-------- circ/returns.pl | 14 ++++---- .../prog/en/modules/circ/returns.tt | 3 +- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 10db0d226a..cce0bfcd4a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2175,6 +2175,7 @@ sub AddReturn { else { $messages->{'WrongTransfer'} = $transfer->tobranch; $messages->{'WrongTransferItem'} = $item->itemnumber; + $messages->{'TransferTrigger'} = $transfer->reason; } } else { @@ -3589,19 +3590,24 @@ This function validate the line of brachtransfer but with the wrong destination sub updateWrongTransfer { my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_; - my $dbh = C4::Context->dbh; -# first step validate the actual line of transfert . - my $sth = - $dbh->prepare( - "update branchtransfers set datearrived = now(),tobranch=?,comments='wrongtransfer' where itemnumber= ? AND datearrived IS NULL" - ); - $sth->execute($FromLibrary,$itemNumber); - -# second step create a new line of branchtransfer to the right location . - ModItemTransfer($itemNumber, $FromLibrary, $waitingAtLibrary); - -#third step changing holdingbranch of item - my $item = Koha::Items->find($itemNumber)->holdingbranch($FromLibrary)->store; + + # 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 = Koha::Item::Transfer->new( + { + itemnumber => $itemNumber, + daterequested => dt_from_string, + datesent => dt_from_string, + frombranch => $FromLibrary, + tobranch => $transfer->tobranch, + reason => $transfer->reason, + comments => $transfer->comments + } + )->store(); } =head2 CalcDateDue diff --git a/circ/returns.pl b/circ/returns.pl index 94e4b5e287..6de69293a3 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -132,11 +132,6 @@ foreach ( $query->param ) { ############ # Deal with the requests.... - -if ($query->param('WT-itemNumber')){ - updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From')); -} - my $itemnumber = $query->param('itemnumber'); if ( $query->param('reserve_id') ) { my $borrowernumber = $query->param('borrowernumber'); @@ -389,12 +384,18 @@ if ( $messages->{'Wrongbranch'} ){ # case of wrong transfert, if the document wasn't transferred to the right library (according to branchtransfer (tobranch) BDD) if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { + + # Trigger modal to prompt librarian $template->param( WrongTransfer => 1, TransferWaitingAt => $messages->{'WrongTransfer'}, WrongTransferItem => $messages->{'WrongTransferItem'}, + trigger => $messages->{'TransferTrigger'}, ); + # Update the transfer to reflect the new item holdingbranch + updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch); + my $reserve = $messages->{'ResFound'}; if ( $reserve ) { my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} ); @@ -402,9 +403,6 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { patron => $patron, ); } - $template->param( - wtransfertFrom => $userenv_branch, - ); } # diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 0fdb3fd6c6..9ce320dcd9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -432,7 +432,7 @@