From 3fbc212d634ceac3d7d79d7a1dca09528cda7c82 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 16 Jan 2020 13:56:41 +0000 Subject: [PATCH] Bug 24298: Record transfer triggers for returns This patch adds handling to catch transfers that may have been triggered on item return. Test Plan: 1) Enable AutomaticItemReturn and accompanying system preference 2) Return an item to the wrong branch and note the transfer 3) Check the database for the new trigger value Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Circulation.pm | 6 ++++-- C4/Items.pm | 13 ++++++------- C4/SIP/ILS/Transaction/Checkin.pm | 3 ++- circ/returns.pl | 4 +++- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 1 + 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index d506e72a14..2c75ec68c4 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1898,6 +1898,7 @@ sub AddReturn { # get the proper branch to which to return the item my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch; # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) + my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef; my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not my $patron_unblessed = $patron ? $patron->unblessed : {}; @@ -2146,12 +2147,13 @@ sub AddReturn { (C4::Context->preference("UseBranchTransferLimits") and ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType ) )) { - $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch; + $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger; $debug and warn "item: " . Dumper($item_unblessed); - ModItemTransfer($item->itemnumber, $branch, $returnbranch); + ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger); $messages->{'WasTransfered'} = 1; } else { $messages->{'NeedsTransfer'} = $returnbranch; + $messages->{'TransferTrigger'} = $transfer_trigger; } } diff --git a/C4/Items.pm b/C4/Items.pm index f83851fcd2..8ed1c5efed 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -538,15 +538,14 @@ sub ModItem { =head2 ModItemTransfer - ModItemTransfer($itenumber, $frombranch, $tobranch); + ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger); -Marks an item as being transferred from one branch -to another. +Marks an item as being transferred from one branch to another and records the trigger. =cut sub ModItemTransfer { - my ( $itemnumber, $frombranch, $tobranch ) = @_; + my ( $itemnumber, $frombranch, $tobranch, $trigger ) = @_; my $dbh = C4::Context->dbh; my $item = Koha::Items->find( $itemnumber ); @@ -558,9 +557,9 @@ sub ModItemTransfer { #new entry in branchtransfers.... my $sth = $dbh->prepare( - "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch) - VALUES (?, ?, NOW(), ?)"); - $sth->execute($itemnumber, $frombranch, $tobranch); + "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch, reason) + VALUES (?, ?, NOW(), ?, ?)"); + $sth->execute($itemnumber, $frombranch, $tobranch, $trigger); ModItem({ holdingbranch => $frombranch }, undef, $itemnumber, { log_action => 0 }); ModDateLastSeen($itemnumber); diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index f0e8bbdf49..08aaddb7ca 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -121,7 +121,8 @@ sub do_checkin { $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id}); ModItemTransfer( $messages->{ResFound}->{itemnumber}, $branch, - $messages->{ResFound}->{branchcode} + $messages->{ResFound}->{branchcode}, + $messages->{TransferTrigger}, ); } diff --git a/circ/returns.pl b/circ/returns.pl index 65093b9d56..456d0d1195 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -229,7 +229,8 @@ if ($dotransfer){ # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer my $transferitem = $query->param('transferitem'); my $tobranch = $query->param('tobranch'); - ModItemTransfer($transferitem, $userenv_branch, $tobranch); + my $trigger = $query->param('trigger'); + ModItemTransfer($transferitem, $userenv_branch, $tobranch, $trigger); } if ($canceltransfer){ @@ -368,6 +369,7 @@ if ( $messages->{'NeedsTransfer'} ){ $template->param( found => 1, needstransfer => $messages->{'NeedsTransfer'}, + trigger => $messages->{'TransferTrigger'}, itemnumber => $itemnumber, ); } 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 2a9717e891..7a9a063064 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -518,6 +518,7 @@ + [% INCLUDE all_checkin_messages %]