@@ -, +, @@ --- C4/Reserves.pm | 4 ++-- t/db_dependent/Reserves.t | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -1195,8 +1195,8 @@ sub IsAvailableForItemLevelRequest { # FIXME - a lot of places in the code do this # or something similar - need to be # consolidated - my $itemtype = $item->effective_itemtype; - my $notforloan_per_itemtype = Koha::ItemTypes->find($itemtype)->notforloan; + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); + my $notforloan_per_itemtype = defined $itemtype ? $itemtype->notforloan : 0; return 0 if $notforloan_per_itemtype || --- a/t/db_dependent/Reserves.t +++ a/t/db_dependent/Reserves.t @@ -17,9 +17,10 @@ use Modern::Perl; -use Test::More tests => 62; +use Test::More tests => 64; use Test::MockModule; use Test::Warn; +use Test::Exception; use t::lib::Mocks; use t::lib::TestBuilder; @@ -533,6 +534,13 @@ $item = Koha::Items->find($itemnumber); ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" ); +# Tests for items not for loan status, bug 24331 +my $item_no_type = $builder->build_sample_item({ itype => undef }); +lives_ok{ C4::Reserves::IsAvailableForItemLevelRequest($item_no_type, $patron) } "Reserving a book on item level with no itemtype"; +my $itemtype_notforloan = $builder->build_object({ class => 'Koha::ItemTypes', value => { notforloan => 1 } })->itemtype; +my $item_notforloan = $builder->build_sample_item({ itype => $itemtype_notforloan }); +is( C4::Reserves::IsAvailableForItemLevelRequest($item_notforloan, $patron), 0, "Item not available if itemtype notforloan" ); + my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode }; t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); --