From 3b0505247ac358067a14a8b2edba087f212daad5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 28 Apr 2022 05:48:33 +0000 Subject: [PATCH] Bug 30636: Show notforloan availability correctly in ILS-DI This patch adds the Koha::Item->is_notforloan() method which checks the item status of "notforloan" and it checks the effective item type to see if it's marked as "notforloan". This change brings ILS-DI in line with the catalogue which displays "Not for loan" for both those scenarios. 0. Don't apply patch yet 1. Enable ILS-DI system preference http://localhost:8081/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ILS-DI 2. Change Item types to "Not for Loan" for Books http://localhost:8081/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=BK 3. Note that book is listed as "Not for loan" in catalogue http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29&searchid=scs_1651115075364 4. Note that book is listed as "available" via ILS-DI http://localhost:8080/cgi-bin/koha/ilsdi.pl?service=GetAvailability&id=29&id_type=bib 5. Apply patch and restart starman (ie koha-plack --restart kohadev) 6. Note that book is listed as "not available" and "Not for loan" via ILS-DI http://localhost:8080/cgi-bin/koha/ilsdi.pl?service=GetAvailability&id=29&id_type=bib -- 7. prove t/db_dependent/Koha/Item.t Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/ILSDI/Services.pm | 2 +- Koha/Item.pm | 28 ++++++++++++++++++++++++++++ t/db_dependent/Koha/Item.t | 20 +++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 02fe8e12ed..61f8e34523 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -972,7 +972,7 @@ sub _availability { my $location = $library ? $library->branchname : ''; my $itemcallnumber = $item->itemcallnumber; - if ( $item->notforloan ) { + if ( $item->is_notforloan ) { return ( $biblionumber, __('not available'), __('Not for loan'), $location, $itemcallnumber ); } elsif ( $item->onloan ) { return ( $biblionumber, __('not available'), __('Checked out'), $location, $itemcallnumber ); diff --git a/Koha/Item.pm b/Koha/Item.pm index 2cefac59be..16d6f95bed 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1651,6 +1651,34 @@ sub check_recalls { return $recall; } +=head3 is_notforloan + + my $is_notforloan = $item->is_notforloan; + +Determine whether or not this item is "notforloan" based on +the item's notforloan status or its item type + +=cut + +sub is_notforloan { + my ( $self ) = @_; + my $is_notforloan = 0; + + if ( $self->notforloan ){ + $is_notforloan = 1; + } + else { + my $itemtype = $self->itemtype; + if ($itemtype){ + if ( $itemtype->notforloan ){ + $is_notforloan = 1; + } + } + } + + return $is_notforloan; +} + =head3 _type =cut diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 8be4d4525c..cbe52ed63e 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 15; +use Test::More tests => 16; use Test::Exception; use Test::MockModule; @@ -1454,3 +1454,21 @@ subtest 'Recalls tests' => sub { $schema->storage->txn_rollback; }; +subtest 'Notforloan tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $item1 = $builder->build_sample_item; + $item1->update({ notforloan => 0 }); + $item1->itemtype->notforloan(0); + is ( $item1->is_notforloan, 0, 'Notforloan is correctly false by item status and item type'); + $item1->update({ notforloan => 1 }); + is ( $item1->is_notforloan, 1, 'Notforloan is correctly true by item status'); + $item1->update({ notforloan => 0 }); + $item1->itemtype->update({ notforloan => 1 }); + is ( $item1->is_notforloan, 1, 'Notforloan is correctly true by item type'); + + $schema->storage->txn_rollback; +}; -- 2.39.5