From 3c22d3d2a82903dc00e64f7dc1c5c24b7682d9c2 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 Signed-off-by: Sonia BOUIS --- C4/Reserves.pm | 15 +++++++- opac/opac-detail.pl | 12 +++++- .../Holds/DisallowHoldIfItemsAvailable.t | 44 +++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 78f5ca3..cf5c3df 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1115,6 +1115,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, @@ -1131,6 +1132,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 @@ -1174,7 +1176,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/opac/opac-detail.pl b/opac/opac-detail.pl index d371f44..ab5de4c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -459,9 +459,19 @@ if ($session->param('busc')) { } } +my $itemsWaitingOrInTransit = Koha::Holds->search( + { + biblionumber => $biblionumber, + found => ['W', 'T'] + })->count(); + +foreach my $item ( Koha::Items->search(biblionumber => $biblionumber) ) { + $itemsWaitingOrInTransit = 1 if $item->get_transfer; +} + $template->param( ItemsIssued => CountItemsIssued( $biblionumber ), - ItemsWaitingOrInTransit => Koha::Holds->search({biblionumber => $biblionumber, found => ['W', 'T']})->count(), + ItemsWaitingOrInTransit => $itemsWaitingOrInTransit, OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"), OPACShowBarcode => C4::Context->preference("OPACShowBarcode") ); 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