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; +};