* 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,
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
return $self->{_subscriptions};
}
+=head3 hasItemswaitingOrInTransit
+
+=cut
+
+sub hasItemswaitingOrInTransit {
+ my ( $self ) = @_;
+
+ if ( Koha::Holds->search({ biblionumber => $self->id,
+ found => ['W', 'T'] })->count ) {
+ return 1;
+ }
+
+ foreach my $item ( $self->items ) {
+ return 1 if $item->get_transfer;
+ }
+
+ return 0;
+}
=head3 type
[% UNLESS ( norequests ) %]
[% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
[% IF Koha.Preference( 'RequestOnOpac' ) == 1 %]
- [% IF ( AllowOnShelfHolds OR ItemsIssued ) %]
+ [% IF ( ReservableItems ) %]
<li><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% biblio.biblionumber %]">Place hold</a></li>
[% END %]
[% END %]
}
}
-
-$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
-$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
+$template->param(
+ OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"),
+);
# adding items linked via host biblios
};
}
+my $allow_onshelf_holds;
if ( not $viewallitems and @items > $max_items_to_display ) {
$template->param(
too_many_items => 1,
items_count => scalar( @items ),
);
} else {
- my $allow_onshelf_holds;
my $patron = Koha::Patrons->find( $borrowernumber );
for my $itm (@items) {
$itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
push @itemloop, $itm;
}
}
- $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
}
+my $itemsWaitingOrInTransit = Koha::Biblios->find($biblionumber)->hasItemswaitingOrInTransit || 0;
+my $itemsIssued = CountItemsIssued( $biblionumber );
+$template->param( 'ReservableItems' => $itemsWaitingOrInTransit || $itemsIssued || $allow_onshelf_holds );
+
# Display only one tab if one items list is empty
if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
$template->param(SeparateHoldings => 0);
use C4::Circulation;
use Koha::IssuingRule;
-use Test::More tests => 5;
+use Test::More tests => 7;
use t::lib::TestBuilder;
use t::lib::Mocks;
};
}
+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;
use Modern::Perl;
-use Test::More tests => 2;
+use Test::More tests => 3;
use C4::Reserves;
is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
};
+subtest 'waiting_or_in_transit' => sub {
+ plan tests => 4;
+ my $biblio = $builder->build( { source => 'Biblio' } );
+ my $item = $builder->build({
+ source => 'Item',
+ value => {
+ biblionumber => $biblio->{biblionumber}
+ }
+ });
+ my $reserve = $builder->build({
+ source => 'Reserve',
+ value => {
+ biblionumber => $biblio->{biblionumber},
+ found => undef
+ }
+ });
+
+ $reserve = Koha::Holds->find($reserve->{reserve_id});
+ $biblio = Koha::Biblios->find($biblio->{biblionumber});
+
+ is($biblio->hasItemswaitingOrInTransit, 0, 'Item is neither waiting nor in transit');
+
+ $reserve->found('W')->store;
+ is($biblio->hasItemswaitingOrInTransit, 1, 'Item is waiting');
+
+ $reserve->found('T')->store;
+ is($biblio->hasItemswaitingOrInTransit, 1, 'Item is in transit');
+
+ my $transfer = $builder->build({
+ source => 'Branchtransfer',
+ value => {
+ itemnumber => $item->{itemnumber},
+ datearrived => undef
+ }
+ });
+ my $t = Koha::Database->new()->schema()->resultset( 'Branchtransfer' )->find($transfer->{branchtransfer_id});
+ $reserve->found(undef)->store;
+ is($biblio->hasItemswaitingOrInTransit, 1, 'Item has transfer');
+};
+
$schema->storage->txn_rollback;