From 13ae42fca8677dff317470e1bdb864255552e83b Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Fri, 6 Oct 2017 13:00:33 +0000 Subject: [PATCH] Bug 4319 followup - [OPAC] allow to holds items in transit Changes on C4::Reserves::IsAvailableForItemLevelRequest Make sure this tests pass: - t/db_dependent/Reserves.t - t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t --- C4/Reserves.pm | 15 +++++++- .../Holds/DisallowHoldIfItemsAvailable.t | 44 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index fbf03fb..ab07840 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1119,6 +1119,7 @@ item-level hold request. An item is available if * it is not lost AND * it is not damaged AND * it is not withdrawn AND +* a waiting or in transit reserve is placed on * does not have a not for loan value > 0 Need to check the issuingrules onshelfholds column, @@ -1135,6 +1136,7 @@ and canreservefromotherbranches. sub IsAvailableForItemLevelRequest { my $item = shift; my $borrower = shift; + my $flag = shift; my $dbh = C4::Context->dbh; # must check the notforloan setting of the itemtype @@ -1178,7 +1180,18 @@ sub IsAvailableForItemLevelRequest { return $any_available ? 0 : 1; } - return $item->{onloan} || GetReserveStatus($item->{itemnumber}) eq "Waiting"; + if ($item->{onloan}) { + return 1; + } + + if (Koha::Holds->search({itemnumber => $item->{itemnumber}, + found => ['W', 'T']}, + {order_by => {-asc => 'priority'}})) { + return 1; + } + + return 0; + return GetReserveStatus($item->{itemnumber}) eq "Waiting"; } =head2 OnShelfHoldsAllowed diff --git a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t index ec76403..e8791de 100755 --- a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t +++ b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t @@ -7,7 +7,7 @@ use C4::Items; use C4::Circulation; use Koha::IssuingRule; -use Test::More tests => 4; +use Test::More tests => 5; use t::lib::TestBuilder; @@ -114,5 +114,47 @@ AddIssue( $borrower2, $item2->{barcode} ); $is = IsAvailableForItemLevelRequest( $item1, $borrower1); is( $is, 1, "Item can be held, no items available" ); +my $biblio = $builder->build({ + source => 'Biblio', +}); + +my $item3 = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + itemlost => 0, + notforloan => 0, + withdrawn => 0, + damaged => 0, + onloan => 0 + } +}); + +my $hold = $builder->build({ + source => 'Reserve', + value =>{ + itemnumber => $item3->{itemnumber}, + found => 'T' + } +}); + +$dbh->do("DELETE FROM issuingrules"); +$rule = Koha::IssuingRule->new( + { + categorycode => '*', + itemtype => '*', + branchcode => '*', + maxissueqty => 99, + issuelength => 7, + lengthunit => 8, + reservesallowed => 99, + onshelfholds => 0, + } +); +$rule->store(); + +$is = IsAvailableForItemLevelRequest( $item3, $borrower1, 'ici'); +is( $is, 1, "Item can be held, items in transit are not available" ); + # Cleanup $schema->storage->txn_rollback; -- 2.7.4