@@ -, +, @@ --- C4/Circulation.pm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -1717,13 +1717,13 @@ sub AddReturn { $branch = C4::Context->userenv->{'branch'} unless $branch; # we trust userenv to be a safe fallback/default my $messages; my $borrower; - my $biblio; my $doreturn = 1; my $validTransfert = 0; my $stat_type = 'return'; # get information on item my $itemnumber = GetItemnumberFromBarcode( $barcode ); + my $biblio = GetBiblioFromItemNumber($itemnumber); unless ($itemnumber) { return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower. bail out. } @@ -1773,6 +1773,30 @@ sub AddReturn { return ( $doreturn, $messages, $issue, $borrower ); } + # 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 = $biblio->{itemtype}; + $branchtransferlimitvalue = $item->{itype} + if C4::Context->preference("item-level_itypes") + && C4::Context->preference("BranchTransferLimitsType") eq 'itemtype'; + $branchtransferlimitvalue = $item->{ccode} + if C4::Context->preference("item-level_itypes") + && C4::Context->preference("BranchTransferLimitsType") eq 'ccode'; + if ( $hbr ne $branch + && ( + C4::Context->preference("IndependentBranches") + or ( C4::Context->preference("UseBranchTransferLimits") + and not IsBranchTransferAllowed($hbr, $branch, $branchtransferlimitvalue ) ) + ) + ) { + $messages->{'Wrongbranch'} = { + Wrongbranch => $branch, + Rightbranch => $message + }; + $doreturn = 0; + return ( $doreturn, $messages, $issue, $borrower ); + } + if ( $item->{'withdrawn'} ) { # book has been cancelled $messages->{'withdrawn'} = 1; $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems"); @@ -3225,7 +3249,6 @@ Code is either an itemtype or collection doe depending on the pref BranchTransfe sub IsBranchTransferAllowed { my ( $toBranch, $fromBranch, $code ) = @_; - if ( $toBranch eq $fromBranch ) { return 1; } ## Short circuit for speed. my $limitType = C4::Context->preference("BranchTransferLimitsType"); --