Skip to content

Commit

Permalink
holds policies fixes
Browse files Browse the repository at this point in the history
* use item branch instead of patron's branch to
look up the applicable hold policies - this makes
requesting in the OPAC consistent with the intranet.
* when generating pick list using build_holds_queue.pl, only match items
to patrons if request is allowed.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
  • Loading branch information
Galen Charlton committed Feb 9, 2009
1 parent bf17eb3 commit b50051a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions misc/cronjobs/holds/build_holds_queue.pl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ =head2 GetPendingHoldRequestsForBib
branchcode
reservedate
reservenotes
borrowerbranch
The arrayref is sorted in order of increasing priority.
Expand All @@ -118,8 +119,10 @@ sub GetPendingHoldRequestsForBib {

my $dbh = C4::Context->dbh;

my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, branchcode, reservedate, reservenotes
my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, reserves.branchcode,
reservedate, reservenotes, borrowers.branchcode AS borrowerbranch
FROM reserves
JOIN borrowers USING (borrowernumber)
WHERE biblionumber = ?
AND found IS NULL
AND priority > 0
Expand Down Expand Up @@ -190,7 +193,9 @@ sub GetItemsAvailableToFillHoldRequestsForBib {
$sth->execute(@params);

my $items = $sth->fetchall_arrayref({});
return [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ];
$items = [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ];
map { my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype}); $_->{holdallowed} = $rule->{holdallowed}; $rule->{holdallowed} != 0 } @$items;
return [ grep { $_->{holdallowed} != 0 } @$items ];
}

=head2 MapItemsToHoldRequests
Expand Down Expand Up @@ -268,7 +273,10 @@ sub MapItemsToHoldRequests {

# look for local match first
my $pickup_branch = $request->{branchcode};
if (exists $items_by_branch{$pickup_branch}) {
if (exists $items_by_branch{$pickup_branch} and
not ($items_by_branch{$pickup_branch}->[0]->{holdallowed} == 1 and
$request->{borrowerbranch} ne $items_by_branch{$pickup_branch}->[0]->{homebranch})
) {
my $item = pop @{ $items_by_branch{$pickup_branch} };
delete $items_by_branch{$pickup_branch} if scalar(@{ $items_by_branch{$pickup_branch} }) == 0;
$item_map{$item->{itemnumber}} = {
Expand All @@ -289,7 +297,9 @@ sub MapItemsToHoldRequests {
@pull_branches = sort keys %items_by_branch;
}
foreach my $branch (@pull_branches) {
next unless exists $items_by_branch{$branch};
next unless exists $items_by_branch{$branch} and
not ($items_by_branch{$branch}->[0]->{holdallowed} == 1 and
$request->{borrowerbranch} ne $items_by_branch{$branch}->[0]->{homebranch});
my $item = pop @{ $items_by_branch{$branch} };
delete $items_by_branch{$branch} if scalar(@{ $items_by_branch{$branch} }) == 0;
$item_map{$item->{itemnumber}} = {
Expand Down
2 changes: 1 addition & 1 deletion opac/opac-reserve.pl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ($$$)
# If there is no loan, return and transfer, we show a checkbox.
$item->{notforloan} = $item->{notforloan} || 0;

my $branchitemrule = GetBranchItemRule( $borr->{'branchcode'}, $item->{'itype'} );
my $branchitemrule = GetBranchItemRule( $item->{'homebranch'}, $item->{'itype'} );
my $policy_holdallowed = 1;

if ( $branchitemrule->{'holdallowed'} == 0 ||
Expand Down

0 comments on commit b50051a

Please sign in to comment.