@@ -, +, @@ --- C4/Reserves.pm | 5 +++++ Koha/Hold.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -810,6 +810,11 @@ sub CheckReserves { my $priority = 10000000; foreach my $res (@reserves) { + + #Before allocating to bib-level hold check if reserve respects hold rule, i.e. can patron category/item type combination allow reserves + my $checkreserve = Koha::Hold->check_if_existing_hold_matches_issuingrules( $res->{'borrowernumber'}, $itemnumber ); + next unless ($checkreserve eq 'OK'); + if ( $res->{'itemnumber'} && $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) { if ($res->{'found'} eq 'W') { return ( "Waiting", $res, \@reserves ); # Found it, it is waiting --- a/Koha/Hold.pm +++ a/Koha/Hold.pm @@ -337,6 +337,46 @@ sub is_suspended { return $self->suspend(); } +=head3 check_if_existing_hold_matches_issuingrules + +my $checkreserve = Koha::Hold->check_if_existing_hold_matches_issuingrules($res->{'borrowernumber'}, $itemnumber ); + +Upon checking in an item of a bibliographic record with a biblio-level hold on it, check if a bib-level hold can be allocated to a patron based on the current values in the issuingrules table + +=cut + +sub check_if_existing_hold_matches_issuingrules { + my ( $self, $borrowernumber, $itemnumber ) = @_; + + #Get patron and item objects + my $patron = Koha::Patrons->find( $borrowernumber ); + my $item = Koha::Items->find( $itemnumber ); + $item = $item->unblessed(); + + #Get branchcode + my $branchcode; + my $controlbranch = C4::Context->preference('ReservesControlBranch'); + + if ( $controlbranch eq "ItemHomeLibrary" ) { + $branchcode = $item->{homebranch}; + } + elsif ( $controlbranch eq "PatronLibrary" ) { + $branchcode = $patron->{branchcode}; + } + + my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ + branchcode => $branchcode, + categorycode => $patron->categorycode, + itemtype => $item->{itype}, + }); + + #Check if the patron catgeory/item type combination is valid + if ( ($issuingrule->reservesallowed || $issuingrule->holds_per_record) == 0 ) { + return 'InvalidHold'; + } else { + return 'OK'; + } +} =head3 cancel --