Bug 9532: fix reservability check when bib-level item types are in use

When itemtype is defined on biblio (item-level_itypes syspref), the
method C4::Reserves::CanItemBeReserved uses item->{itemtype}. But
ithe item comes from C4::Items::GetItem and it does not have an
'itemtype' key; in this method the item type value is always in
'itype' key.

This patch corrects it.

Test plan:

You should have itemtype on biblio and 'item-level_itypes' syspref
set to biblio.

This test plan is with ReservesControlBranch on ItemHomeLibrary.
- Choose a branch, a borrower category and an item type, for example
  'NYC', 'CHILD' and 'DVD'
- Set an issuing rule for 'NYC', CHILD' and 'DVD' with 'Holds allowed'
  set to 10
- Set an issuing rule for 'NYC', CHILD' and all item types with
  'Holds allowed' set to 0
- Choose an item of a biblio with itemtype 'DVD', that can be reserved,
  with 'NYC' as homebranch
- Choose a borrower with category 'CHILD'
- Try to request the item for the borrower
=> without the patch, you can
=> with the patch, you can't
You may check reserve is allowed with 'Holds allowed' > 0 on issuing
rule for 'DVD'.

Signed-off-by: Liz Rea <liz@catalyst.net.nz>
Great test plan - thanks!

Confirmed the bug, and the fix. Looks good to me.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Fridolyn SOMERS 2013-02-01 17:52:11 +01:00 committed by Galen Charlton
parent 2afadcc358
commit 7acd7f43a7

View file

@ -463,9 +463,11 @@ sub CanItemBeReserved{
my ($borrowernumber, $itemnumber) = @_; my ($borrowernumber, $itemnumber) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $ruleitemtype; # itemtype of the matching issuing rule
my $allowedreserves = 0; my $allowedreserves = 0;
# we retrieve borrowers and items informations # # we retrieve borrowers and items informations #
# item->{itype} will come for biblioitems if necessery
my $item = GetItem($itemnumber); my $item = GetItem($itemnumber);
# If an item is damaged and we don't allow holds on damaged items, we can stop right here # If an item is damaged and we don't allow holds on damaged items, we can stop right here
@ -474,7 +476,7 @@ sub CanItemBeReserved{
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);
my $controlbranch = C4::Context->preference('ReservesControlBranch'); my $controlbranch = C4::Context->preference('ReservesControlBranch');
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; my $itemtypefield = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
# we retrieve user rights on this itemtype and branchcode # we retrieve user rights on this itemtype and branchcode
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed
@ -498,8 +500,6 @@ sub CanItemBeReserved{
"; ";
my $itemtype = $item->{$itype};
my $categorycode = $borrower->{categorycode};
my $branchcode = ""; my $branchcode = "";
my $branchfield = "reserves.branchcode"; my $branchfield = "reserves.branchcode";
@ -512,25 +512,25 @@ sub CanItemBeReserved{
} }
# we retrieve rights # we retrieve rights
$sth->execute($categorycode, $itemtype, $branchcode); $sth->execute($borrower->{'categorycode'}, $item->{'itype'}, $branchcode);
if(my $rights = $sth->fetchrow_hashref()){ if(my $rights = $sth->fetchrow_hashref()){
$itemtype = $rights->{itemtype}; $ruleitemtype = $rights->{itemtype};
$allowedreserves = $rights->{reservesallowed}; $allowedreserves = $rights->{reservesallowed};
}else{ }else{
$itemtype = '*'; $ruleitemtype = '*';
} }
# we retrieve count # we retrieve count
$querycount .= "AND $branchfield = ?"; $querycount .= "AND $branchfield = ?";
$querycount .= " AND $itype = ?" if ($itemtype ne "*"); $querycount .= " AND $itemtypefield = ?" if ($ruleitemtype ne "*");
my $sthcount = $dbh->prepare($querycount); my $sthcount = $dbh->prepare($querycount);
if($itemtype eq "*"){ if($ruleitemtype eq "*"){
$sthcount->execute($borrowernumber, $branchcode); $sthcount->execute($borrowernumber, $branchcode);
}else{ }else{
$sthcount->execute($borrowernumber, $branchcode, $itemtype); $sthcount->execute($borrowernumber, $branchcode, $ruleitemtype);
} }
my $reservecount = "0"; my $reservecount = "0";