Bug 19301: Move C4::Reserves::OnShelfHoldsAllowed to get_onshelfholds_policy

Following the pattern introduced by bug 19300, we are going to move the
OnShelfHoldsAllowed logic to Koha::IssuingRules->get_onshelfholds_policy

Test plan:
Make sure the onshelfholds policy is correct when placing a hold

Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2017-09-11 16:02:19 -03:00
parent a3c922c2a1
commit 39e1fbcbe9
6 changed files with 30 additions and 7 deletions

View File

@ -1101,10 +1101,12 @@ sub IsAvailableForItemLevelRequest {
# FIXME - a lot of places in the code do this
# or something similar - need to be
# consolidated
my $itype = _get_itype($item);
my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
my $item_object = Koha::Items->find( $item->{itemnumber } );
my $itemtype = $item_object->effective_itemtype;
my $notforloan_per_itemtype
= $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
undef, $itype);
undef, $itemtype);
return 0 if
$notforloan_per_itemtype ||
@ -1113,7 +1115,7 @@ sub IsAvailableForItemLevelRequest {
$item->{withdrawn} ||
($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
my $on_shelf_holds = _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch});
my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
if ( $on_shelf_holds == 1 ) {
return 1;

View File

@ -100,6 +100,21 @@ sub get_opacitemholds_policy {
return $issuing_rule ? $issuing_rule->opacitemholds : undef;
}
sub get_onshelfholds_policy {
my ( $class, $params ) = @_;
my $item = $params->{item};
my $itemtype = $item->effective_itemtype;
my $patron = $params->{patron};
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{
( $patron ? ( categorycode => $patron->categorycode ) : () ),
itemtype => $itemtype,
branchcode => $item->holdingbranch
}
);
return $issuing_rule ? $issuing_rule->onshelfholds : undef;
}
=head3 type
=cut

View File

@ -52,6 +52,8 @@ use C4::Reserves;
use C4::Acquisition;
use C4::Serials; # uses getsubscriptionfrom biblionumber
use C4::Koha;
use Koha::IssuingRules;
use Koha::Items;
use Koha::ItemTypes;
use Koha::Patrons;
use Koha::RecordProcessor;
@ -169,6 +171,7 @@ my $res = GetISBDView({
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
my $patron = Koha::Patrons->find( $loggedinuser );
for my $itm (@items) {
my $item = Koha::Items->find( $itm->{itemnumber} );
$norequests = 0
if $norequests
&& !$itm->{'withdrawn'}
@ -177,7 +180,7 @@ for my $itm (@items) {
&& !$itemtypes->{$itm->{'itype'}}->{notforloan}
&& $itm->{'itemnumber'};
$allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) )
$allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
unless $allow_onshelf_holds;
}

View File

@ -132,7 +132,8 @@ if(my $cart_list = $query->cookie("bib_list")){
my $allow_onshelf_holds;
my $patron = Koha::Patrons->find( $loggedinuser );
for my $itm (@all_items) {
$allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) );
my $items = Koha::Items->find( $itm->{itemnumber} );
$allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
last if $allow_onshelf_holds;
}

View File

@ -661,6 +661,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
} else {
my $patron = Koha::Patrons->find( $borrowernumber );
for my $itm (@items) {
my $item = Koha::Items->find( $itm->{itemnumber} );
$itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
$itm->{priority} = $priority{ $itm->{itemnumber} };
$norequests = 0
@ -671,7 +672,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
&& !$itemtypes->{$itm->{'itype'}}->{notforloan}
&& $itm->{'itemnumber'};
$allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) )
$allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
unless $allow_onshelf_holds;
# get collection code description, too

View File

@ -31,6 +31,7 @@ use C4::XSLT;
use Koha::Biblios;
use Koha::Biblioitems;
use Koha::IssuingRules;
use Koha::Items;
use Koha::ItemTypes;
use Koha::Patrons;
@ -319,7 +320,7 @@ if ( $op eq 'view' ) {
my $items = $biblio->items;
while ( my $item = $items->next ) {
$this_item->{allow_onshelf_holds} = C4::Reserves::OnShelfHoldsAllowed($item->unblessed, $patron);
$this_item->{allow_onshelf_holds} = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
last if $this_item->{allow_onshelf_holds};
}