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 <bgkriegel@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2020-01-16 13:56:41 +00:00
parent 26b64bf8b4
commit 3fbc212d63
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
5 changed files with 16 additions and 11 deletions

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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},
);
}

View file

@ -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,
);
}

View file

@ -518,6 +518,7 @@
<input type="hidden" name="tobranch" value="[% returnbranch | html %]" />
<input type="hidden" name="transferitem" value="[% itemnumber | html %]" />
<input type="hidden" name="barcode" value="0" />
<input type="hidden" name="trigger" value="[% trigger %]" />
[% INCLUDE all_checkin_messages %]
</div>
<div class="modal-footer">