Bug 31313: Fix availability - OPAC opac-detail

Has to move some code to a method

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-08-01 08:59:53 +02:00 committed by Tomas Cohen Arazi
parent 959f49baf2
commit 70cb4e22c0
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
6 changed files with 33 additions and 18 deletions

View file

@ -44,6 +44,7 @@ use Koha::ItemTypes;
use Koha::Libraries;
use Koha::Patrons;
use Koha::Plugins;
use Koha::Recalls;
use Koha::Result::Boolean;
use Koha::SearchEngine::Indexer;
use Koha::StockRotationItem;
@ -910,6 +911,26 @@ sub has_pending_hold {
return $pending_hold->count ? 1: 0;
}
=head3 has_pending_recall {
my $has_pending_recall
Return if whether has pending recall of not.
=cut
sub has_pending_recall {
my ( $self ) = @_;
# FIXME Must be moved to $self->recalls
return Koha::Recalls->search(
{
item_id => $self->itemnumber,
status => 'waiting',
}
)->count;
}
=head3 as_marc_field
my $field = $item->as_marc_field;

View file

@ -1,4 +1,4 @@
[% IF ( item.damaged or item.datedue or item.itemlost or item.transfertwhen or item.waiting ) %]
[% IF ( item.damaged or item.checkout.date_due or item.itemlost or item.transfertwhen or item.waiting ) %]
<link property="availability" href="http://schema.org/OutOfStock" />
[% ELSIF ( item.withdrawn ) %]
<link property="availability" href="http://schema.org/Discontinued" />

View file

@ -18,8 +18,8 @@
[% END %]
[% IF item.isa('Koha::Item') %]
[% SET datedue = issue.date_due %]
[% SET onsite_checkout = issue.onsite_checkout %]
[% SET datedue = item.checkout.date_due %]
[% SET onsite_checkout = item.checkout.onsite_checkout %]
[% ELSE %]
[% SET datedue = item.datedue || issue.date_due %]
[% SET onsite_checkout = item.onsite_checkout %]
@ -39,7 +39,8 @@
<span class="item-status checkedout">Checked out</span>
[% END %]
[% END %]
[% IF item.avail_for_recall %]<a href="/cgi-bin/koha/opac-recall.pl?biblionumber=[% item.biblionumber | uri %]" class="btn btn-default btn-xs">Recall</a>[% END %]
[%# FIXME We should move avail_for_recall to a Koha::Item method %]
[% IF !item.isa('Koha::Item') AND item.avail_for_recall %]<a href="/cgi-bin/koha/opac-recall.pl?biblionumber=[% item.biblionumber | uri %]" class="btn btn-default btn-xs">Recall</a>[% END %]
[% END %]
[% IF NOT ( item.isa('Koha::Item') ) AND item.transfertwhen %] [%# transfertwhen is set in C4::Search, do not have it for course reserves %]
@ -100,7 +101,7 @@
<span class="item-status pendinghold">Pending hold</span>
[% END %]
[% IF item.has_pending_recall %]
[% IF Koha.Preference('UseRecalls') && item.has_pending_recall %]
[% SET itemavailable = 0 %]
<span class="item-status pendingrecall">Pending recall</span>
[% END %]

View file

@ -1362,7 +1362,7 @@
</td>
[% END # /IF itemdata_uri %]
[% IF ( itemdata_copynumber ) %]<td class="copynumber">[% ITEM_RESULT.copynumber | html %]</td>[% END %]
<td class="status">[% INCLUDE 'item-status-schema-org.inc' item = ITEM_RESULT %][% INCLUDE 'item-status.inc' item = ITEM_RESULT %]</td>
<td class="status">[% INCLUDE 'item-status-schema-org.inc' item = ITEM_RESULT %][% INCLUDE 'item-status.inc' item = ITEM_RESULT.object %]</td>
[% IF ( itemdata_itemnotes ) %]<td class="notes" property="description">[% ITEM_RESULT.itemnotes | $raw %]</td>[% END %]
[% IF ITEM_RESULT.checkout %]
<td class="date_due" data-order="[% ITEM_RESULT.checkout.date_due | html %]">[% ITEM_RESULT.checkout.date_due | $KohaDates as_due_date => 1 %]</td>

View file

@ -79,7 +79,6 @@ use Koha::Virtualshelves;
use Koha::Patrons;
use Koha::Plugins;
use Koha::Ratings;
use Koha::Recalls;
use Koha::Reviews;
use Koha::Serial::Items;
use Koha::SearchEngine::Search;
@ -729,22 +728,13 @@ else {
}
$item_info->{checkout} = $item->checkout;
$item_info->{object} = $item;
my $reserve_status =
C4::Reserves::GetReserveStatus( $item->itemnumber );
if ( $reserve_status eq "Waiting" ) { $item_info->{'waiting'} = 1; }
if ( $reserve_status eq "Reserved" ) { $item_info->{'onhold'} = 1; }
if ( C4::Context->preference('UseRecalls') ) {
my $pending_recall_count = Koha::Recalls->search(
{
item_id => $item->itemnumber,
status => 'waiting',
}
)->count;
if ( $pending_recall_count ) { $item_info->has_pending_recall = 1; }
}
my ( $transfertwhen, $transfertfrom, $transfertto ) =
GetTransfers( $item->itemnumber );
if ( defined($transfertwhen) && $transfertwhen ne '' ) {

View file

@ -1483,7 +1483,7 @@ subtest 'store() tests' => sub {
subtest 'Recalls tests' => sub {
plan tests => 20;
plan tests => 22;
$schema->storage->txn_begin;
@ -1654,6 +1654,7 @@ subtest 'Recalls tests' => sub {
}
)->store;
$recall2->set_waiting( { item => $item1 } );
is( $item1->has_pending_recall, 1, 'Item has pending recall' );
# return a waiting recall
my $check_recall = $item1->check_recalls;
@ -1661,6 +1662,8 @@ subtest 'Recalls tests' => sub {
$recall2->revert_waiting;
is( $item1->has_pending_recall, 0, 'Item does not have pending recall' );
# return recall based on recalldate
$check_recall = $item1->check_recalls;
is( $check_recall->patron_id, $patron1->borrowernumber, "No waiting recall, so oldest recall is returned" );