From b3308ee262a8007413d1b11e0659e8dabbc23668 Mon Sep 17 00:00:00 2001 From: Olivier Crouzet Date: Mon, 9 Sep 2019 16:30:49 +0200 Subject: [PATCH] Bug 7376 Transfer limits should be checked at check-in --- C4/Circulation.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e346e2d..5c4d59b 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1124,6 +1124,8 @@ Check whether the item can be returned to the provided branch =item C<$branch> is the branchcode where the return is taking place +=item C<$itemtype> is the document type of the item + =back Returns: @@ -1139,13 +1141,29 @@ Returns: =cut sub CanBookBeReturned { - my ($item, $branch) = @_; - my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; + my ($item, $branch, $itemtype) = @_; # assume return is allowed to start my $allowed = 1; my $message; + my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; + if ($allowreturntobranch eq 'anywhere') { + # if we try a checkin that would result in a forbidden branchtransfer, refuse the return as well + # first, find branchtransferlimit value for this item + my $branchtransferlimitvalue = (C4::Context->preference("item-level_itypes") && C4::Context->preference("BranchTransferLimitsType") eq 'ccode') ? $item->{ccode} : $itemtype; + if ( $item->{'homebranch'} ne $branch + && ( C4::Context->preference("IndependentBranches") + or ( C4::Context->preference("UseBranchTransferLimits") and not IsBranchTransferAllowed($item->{'homebranch'}, $branch, $branchtransferlimitvalue) ) + ) + ) + { + $allowed = 0; + $message = $item->{'homebranch'}; + return ($allowed, $message); + } + } + # identify all cases where return is forbidden if ($allowreturntobranch eq 'homebranch' && $branch ne $item->{'homebranch'}) { $allowed = 0; @@ -1924,7 +1942,7 @@ sub AddReturn { } # check if the return is allowed at this branch - my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch); + my ($returnallowed, $message) = CanBookBeReturned($item, $branch, $itemtype); unless ($returnallowed){ $messages->{'Wrongbranch'} = { Wrongbranch => $branch, -- 2.1.4