Bug 40475

Summary: Majority of CanBookBeReserved might be dead code?
Product: Koha Reporter: David Cook <dcook>
Component: Hold requestsAssignee: Bugs List <koha-bugs>
Status: RESOLVED INVALID QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: gmcharlt, jonathan.druart, lisette, pedro.amorim, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15516
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description David Cook 2025-07-23 05:01:15 UTC
I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed that the $itemtype in the following line of opac/opac-reserve.pl looks like it'll always be "undef" for "next available" holds:

my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $itemtype } )->{status};
Comment 1 David Cook 2025-07-23 05:06:16 UTC
In reserve/request.pl we just use this code:

my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );

CanItemBeReserved( $patron, $item_object, undef, { get_from_cache => 1 } )->{status};

So it looks like the majority of CanBookBeReserved never runs because $params->{itemtype} will always be null.

But that might be OK, because at the end of CanBookBeReserved we iterate through all the items attached to that bib and we check them using CanItemBeReserved...
Comment 2 David Cook 2025-07-23 05:06:34 UTC
Note we didn't notice this during manual testing but it came up when looking at t/db_dependent/Reserves.t
Comment 3 Jonathan Druart 2025-07-23 08:44:48 UTC
(In reply to David Cook from comment #0)
> I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed
> that the $itemtype in the following line of opac/opac-reserve.pl looks like
> it'll always be "undef" for "next available" holds:
> 
> my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, {
> itemtype => $itemtype } )->{status};

Are you sure?
Turn on AllowHoldItemTypeSelection

https://snipboard.io/sBaKNe.jpg
If I select "Book" here, I hit CanBookBeReserved with itemtype=BK
Comment 4 David Cook 2025-07-24 00:18:51 UTC
(In reply to Jonathan Druart from comment #3)
> (In reply to David Cook from comment #0)
> > I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed
> > that the $itemtype in the following line of opac/opac-reserve.pl looks like
> > it'll always be "undef" for "next available" holds:
> > 
> > my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, {
> > itemtype => $itemtype } )->{status};
> 
> Are you sure?

No, that's why I framed the bug report title as a question. 

> Turn on AllowHoldItemTypeSelection
> 
> https://snipboard.io/sBaKNe.jpg
> If I select "Book" here, I hit CanBookBeReserved with itemtype=BK

Thanks for sharing that. That's really helpful. 

It looks like there are a few bugs in the staff interface: it looks like "./reserve/placerequest.pl" isn't using the itemtype with "CanBookBeReserved", and "request.pl" is sending 2 "itemtype" arguments due to a duplicated "Request specific item type" field, so only the first field will ever work.

I'll raise a different report for those.