From f207da359d5b4730fc05d38bd1c09fdb785eb570 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 3 Oct 2017 14:50:36 +0000 Subject: [PATCH] Bug 4319 - [OPAC] allow to holds waiting items Test plan: - Checkout an item - Place hold on this item, - Return the item - Make sure the hold is waiting (found W) and AllowOnShelfHolds is not to 'Allow' - Check that the button "Place hold" appears in opac detail page of the biblio - do the samewith items/reserves in transit Changes on C4::Reserves::IsAvailableForItemLevelRequest Make sure this tests pass: - t/db_dependent/Reserves.t - t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t Rebased - 2017-12-12 - Alex Arnaud --- C4/Reserves.pm | 12 +++++- .../bootstrap/en/includes/opac-detail-sidebar.inc | 2 +- opac/opac-detail.pl | 17 +++++++- .../Holds/DisallowHoldIfItemsAvailable.t | 49 +++++++++++++++++++++- 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 06cde18..7ceaaf2 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1080,6 +1080,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, @@ -1144,7 +1145,16 @@ 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']})->count ) { + return 1; + } + + return 0; } =head2 OnShelfHoldsAllowed diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index 5e96b0f..a94180c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -3,7 +3,7 @@ [% UNLESS ( norequests ) %] [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] [% IF Koha.Preference( 'RequestOnOpac' ) == 1 %] - [% IF ( AllowOnShelfHolds OR ItemsIssued ) %] + [% IF ( AllowOnShelfHolds OR ItemsIssued OR ItemsWaitingOrInTransit ) %]
  • Place hold
  • [% END %] [% END %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 819e426..deb141d 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -458,9 +458,22 @@ if ($session->param('busc')) { } } +my $itemsWaitingOrInTransit = Koha::Holds->search( + { + biblionumber => $biblionumber, + found => ['W', 'T'] + })->count(); +unless ($itemsWaitingOrInTransit) { + foreach my $item ( Koha::Items->search(biblionumber => $biblionumber) ) { + $itemsWaitingOrInTransit = 1 if $item->get_transfer; + } +} -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); -$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); +$template->param( + ItemsIssued => CountItemsIssued( $biblionumber ), + ItemsWaitingOrInTransit => $itemsWaitingOrInTransit, + OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"), +); # adding items linked via host biblios diff --git a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t index 3c5fd72..3abba34 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 => 5; +use Test::More tests => 7; use t::lib::TestBuilder; use t::lib::Mocks; @@ -213,5 +213,52 @@ AddReturn( $item1->{barcode} ); }; } +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); +is( $is, 1, "Item can be held, items in transit are not available" ); + +Koha::Holds->find($hold->{reserve_id})->found('F')->store; + +$is = IsAvailableForItemLevelRequest( $item3, $borrower1); +is( $is, 0, "Item is neither waiting nor in transit." ); + # Cleanup $schema->storage->txn_rollback; -- 2.7.4