From fe2d7053ea4b56abd523782e42d2f5f7af56092e Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Thu, 29 Dec 2011 15:49:53 +0100 Subject: [PATCH] Bug 7376 Transfer limits should be checked at check-in Test case: * UseBranchTransferLimits must be set * define your branch transfer limit. Refuse transfers from libraryA to libraryB * checkout a book owned by libraryB, from libraryB, with a librarian located at libraryB * move the librarian to libraryA ("Set Library" link top/right) * check-in the book => it's possible whatever your setup After the patch, the behaviour respect the branch transfer limit parameter: you can check-in if you accept transfers, you can't if you refuse them. (Note: IndependantBranches must be OFF, otherwise it's not possible to do the checkin whatever the branch transfer limits) --- C4/Circulation.pm | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9a6f4f2..b0463e6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1480,13 +1480,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. } @@ -1525,7 +1525,18 @@ sub AddReturn { } # if indy branches and returning to different branch, refuse the return - if ($hbr ne $branch && C4::Context->preference("IndependantBranches")){ + # 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=''; + if ( C4::Context->preference("item-level_itypes") && C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ) { + $branchtransferlimitvalue=$item->{itype}; + } elsif (C4::Context->preference("item-level_itypes") && C4::Context->preference("BranchTransferLimitsType") eq 'ccode' ) { + $branchtransferlimitvalue=$item->{ccode}; + } else { + $branchtransferlimitvalue=$biblio->{itemtype}; + } + if (($hbr ne $branch && C4::Context->preference("IndependantBranches")) or (!IsBranchTransferAllowed($hbr, $branch, $branchtransferlimitvalue ))) { $messages->{'Wrongbranch'} = { Wrongbranch => $branch, Rightbranch => $hbr, @@ -2927,7 +2938,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"); -- 1.7.5.4