From aecad4fe4c28fd37fb2f3edd4211adbf98711728 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 Added test plan. Works Ok, trigger saved in database. --- 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 860d965cf1..7a69744a95 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 : {}; @@ -2137,12 +2138,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 a9e2bc243c..392bca5e6c 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -237,7 +237,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){ @@ -376,6 +377,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 29818882c9..fe9b4d498b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -519,6 +519,7 @@ + [% INCLUDE all_checkin_messages %]