From 499a75791bc20143796be85507861486f24f9235 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 30 Aug 2019 17:20:38 +0000 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) Sponsored-by: National Library of Finland --- C4/Circulation.pm | 36 +++++++++++++++---- C4/SIP/ILS/Transaction/Checkin.pm | 3 ++ circ/returns.pl | 3 ++ .../prog/en/modules/circ/returns.tt | 3 ++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c693105df5..3c6f2b1bde 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1132,7 +1132,10 @@ Returns: =item C<$returnallowed> is 0 or 1, corresponding to whether the return is allowed (1) or not (0) -=item C<$message> is the branchcode where the item SHOULD be returned, if the return is not allowed +=item C<$message> is a HASHref of following possible keys: + +C branchcode where the item SHOULD be returned, if the return is not allowed +C transfer limit exists, HASHref of following keys: C, C =back @@ -1144,18 +1147,30 @@ sub CanBookBeReturned { # assume return is allowed to start my $allowed = 1; + my $to_branch = $branch; my $message; # identify all cases where return is forbidden if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) { $allowed = 0; - $message = $item->homebranch; + $message->{toBranch} = $to_branch = $item->homebranch; } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) { $allowed = 0; - $message = $item->holdingbranch; + $message->{toBranch} = $to_branch = $item->holdingbranch; } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) { $allowed = 0; - $message = $item->homebranch; # FIXME: choice of homebranch is arbitrary + $message->{toBranch} = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary + } + + # Make sure there are no branch transfer limits between item's current + # branch (holdinbranch) and the return branch + my $to_library = Koha::Libraries->find($to_branch); + if (!$item->can_be_transferred({ to => $to_library })) { + $allowed = 0; + $message->{transferLimit} = { + from => $item->holdingbranch, + to => $to_branch + }; } return ($allowed, $message); @@ -1803,6 +1818,10 @@ This book has was returned to the wrong branch. The value is a hashref so that C<$messages->{Wrongbranch}->{Wrongbranch}> and C<$messages->{Wrongbranch}->{Rightbranch}> contain the branchcode of the incorrect and correct return library, respectively. +=item C + +A transfer limit exists between item's holding branch and the return branch. + =item C The item was reserved. The value is a reference-to-hash whose keys are @@ -1928,8 +1947,13 @@ sub AddReturn { unless ($returnallowed){ $messages->{'Wrongbranch'} = { Wrongbranch => $branch, - Rightbranch => $message - }; + Rightbranch => $message->{toBranch} + } if $message->{toBranch}; + + if ($message->{'transferLimit'}) { + $messages->{'Transferlimit'} = $message->{'transferLimit'}; + } + $doreturn = 0; return ( $doreturn, $messages, $issue, $patron_unblessed); } diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index f0e8bbdf49..a506919cd0 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -96,6 +96,9 @@ sub do_checkin { $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch}); $self->alert_type('04'); # send to other branch } + if ($messages->{Transferlimit}) { + $self->alert_type('04'); + } if ($messages->{WrongTransfer}) { $self->{item}->destination_loc($messages->{WrongTransfer}); $self->alert_type('04'); # send to other branch diff --git a/circ/returns.pl b/circ/returns.pl index 657229a10e..220c1fda42 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -521,6 +521,9 @@ foreach my $code ( keys %$messages ) { } elsif ( $code eq 'Wrongbranch' ) { } + elsif ( $code eq 'Transferlimit' ) { + $err{transferlimit} = $messages->{'Transferlimit'}; + } elsif ( $code eq 'Debarred' ) { $err{debarred} = $messages->{'Debarred'}; $err{debarcardnumber} = $borrower->{cardnumber}; 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 42d7a19089..e8ed642517 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -611,6 +611,9 @@ [% END %]

Item is withdrawn.

[% END %] + [% IF ( errmsgloo.transferlimit ) %] +

Transfer is forbidden between [% Branches.GetName( holdingbranch ) %] (item's current library) and [% LoginBranchname | html %].

+ [% END %] [% IF ( errmsgloo.debarred ) %]

[% errmsgloo.debarname | html %]([% errmsgloo.debarcardnumber | html %]) is now debarred until [% errmsgloo.debarred | $KohaDates %].

[% END %] -- 2.17.1