Bug 40034: Only check notforloan on itemtype if it exists

This patch makes the code in `CheckReserves` survive the non-existence
of the referenced item type in the `items` table for the passed item.

To test:
1. Apply the regression tests
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Reserves.t
=> FAIL: Tests explode like this:

```
Can't call method "notforloan" on an undefined value at /kohadevbox/koha/C4/Reserves.pm line 870.
```

3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 854783c836)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomas Cohen Arazi 2025-06-02 09:50:19 -03:00 committed by Paul Derscheid
parent 7cc3b371fe
commit 3284f58e95
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 5 additions and 4 deletions

View File

@ -865,10 +865,11 @@ sub CheckReserves {
my $dont_trap = C4::Context->preference('TrapHoldsOnOrder') ? $item->notforloan > 0 : $item->notforloan;
if ( !$dont_trap ) {
my $item_type = $item->effective_itemtype;
if ($item_type) {
return if Koha::ItemTypes->find($item_type)->notforloan;
}
my $effective_item_type = $item->effective_itemtype;
my $item_type = Koha::ItemTypes->find($effective_item_type);
return
if $item_type && $item_type->notforloan;
} else {
return;
}