@@ -, +, @@ -- --- C4/ILSDI/Services.pm | 2 +- Koha/Item.pm | 28 ++++++++++++++++++++++++++++ t/db_dependent/Koha/Item.t | 20 +++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) --- a/C4/ILSDI/Services.pm +++ a/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 ); --- a/Koha/Item.pm +++ a/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 --- a/t/db_dependent/Koha/Item.t +++ a/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; +}; --