@@ -, +, @@
a hold on a record with available items
patron to check out
8) Attempt to place a hold for the item
9) Note you cannot place the hold
10) Check the available item out to another patron
11) Note you can now place a hold for the first patron
---
C4/Reserves.pm | 26 ++++-
.../prog/en/modules/admin/smart-rules.tt | 12 +-
.../Holds/DisallowHoldIfItemsAvailable.t | 122 +++++++++++++++++++++
3 files changed, 157 insertions(+), 3 deletions(-)
create mode 100755 t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t
--- a/C4/Reserves.pm
+++ a/C4/Reserves.pm
@@ -41,6 +41,8 @@ use Koha::Database;
use Koha::Hold;
use Koha::Holds;
use Koha::Libraries;
+use Koha::Items;
+use Koha::Itemtypes;
use List::MoreUtils qw( firstidx any );
use Carp;
@@ -1493,8 +1495,30 @@ sub IsAvailableForItemLevelRequest {
$item->{withdrawn} ||
($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
+ my $on_shelf_holds = _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch});
+
+ if ( $on_shelf_holds == 1 ) {
+ return 1;
+ } elsif ( $on_shelf_holds == 2 ) {
+ my @items =
+ Koha::Items->search( { biblionumber => $item->{biblionumber} } );
+
+ my $any_available = 0;
+
+ foreach my $i (@items) {
+ $any_available = 1
+ unless $i->itemlost
+ || $i->{notforloan} > 0
+ || $i->withdrawn
+ || $i->onloan
+ || GetReserveStatus( $i->id ) eq "Waiting"
+ || ( $i->damaged
+ && !C4::Context->preference('AllowHoldsOnDamagedItems') )
+ || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan;
+ }
- return 1 if _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch});
+ return $any_available ? 0 : 1;
+ }
return $item->{onloan} || GetReserveStatus($item->{itemnumber}) eq "Waiting";
}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
@@ -248,7 +248,14 @@ for="tobranch">Clone these rules to: Edit
@@ -318,7 +325,8 @@ for="tobranch">Clone these rules to:
-
+
+