From 02a8e8cdcdd3e35c4889f7451f83c34152ccea57 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 27 Jun 2024 15:46:31 +0200 Subject: [PATCH] Bug 30274: Prevent non-reservable item to be set as waiting at checkin Test plan: 1. Create a biblio with 2 items: * 1st item: * Barcode: ITEM1 * Item type: TYPE1 * Homebranch and holdingbranch: LIBRARY * 2nd item: * Barcode: ITEM2 * Item type: TYPE2 * Homebranch and holdingbranch: LIBRARY 2. Create a circulation rule for LIBRARY, TYPE1 with "Holds allowed (total)" = 1 3. Create a circulation rule for LIBRARY, TYPE2 with "Holds allowed (total)" = 0 4. Place a biblio-level hold on that biblio with a patron from library LIBRARY. 5. Check in: ITEM2 Without the patch, the "Hold found" popup appears, allowing you to confirm hold for a non-reservable item With the patch, no popup appears. Signed-off-by: Roman Dolny --- C4/Reserves.pm | 10 +++ t/db_dependent/Reserves/CheckReserves.t | 109 ++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100755 t/db_dependent/Reserves/CheckReserves.t diff --git a/C4/Reserves.pm b/C4/Reserves.pm index bc96dc9c3c..c0c5721401 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -928,6 +928,16 @@ sub CheckReserves { next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } ); + my $reservesallowed = Koha::CirculationRules->get_effective_rule_value( + { + itemtype => $item->effective_itemtype, + categorycode => $patron->categorycode, + branchcode => $branch, + rule_name => 'reservesallowed', + } + ); + next unless $reservesallowed; + $priority = $res->{'priority'}; $highest = $res; last if $local_hold_match; diff --git a/t/db_dependent/Reserves/CheckReserves.t b/t/db_dependent/Reserves/CheckReserves.t new file mode 100755 index 0000000000..9a4fc42276 --- /dev/null +++ b/t/db_dependent/Reserves/CheckReserves.t @@ -0,0 +1,109 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More; + +use C4::Reserves; +use Koha::CirculationRules; +use Koha::Database; +use Koha::ItemType; +use t::lib::TestBuilder; + +plan tests => 1; + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'CheckReserves checks circulation rule reservesallowed' => sub { + plan tests => 2; + + $schema->txn_begin; + + # One biblio has 2 items of different itemtype. One is reservable + # (reservesallowed = 1), the other is not (reservesallowed = 0). + # A patron made a reserve at the biblio-level + # CheckReserves, when given the non-reservable item, should NOT return this + # reserve + + my $itemtype_ok = Koha::ItemType->new( { itemtype => 'CHKRES:OK' } ); + $itemtype_ok->store(); + my $itemtype_ko = Koha::ItemType->new( { itemtype => 'CHKRES:KO' } ); + $itemtype_ko->store(); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $biblio = $builder->build_sample_biblio(); + my $item_ok = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->unblessed, + itype => $itemtype_ok->itemtype, + } + ); + my $item_ko = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->branchcode, + itype => $itemtype_ko->itemtype, + } + ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + }, + } + ); + Koha::CirculationRules->set_rule( + { + branchcode => $library->branchcode, + categorycode => $patron->categorycode, + itemtype => $itemtype_ok->itemtype, + rule_name => 'reservesallowed', + rule_value => '1', + } + ); + Koha::CirculationRules->set_rule( + { + branchcode => $library->branchcode, + categorycode => $patron->categorycode, + itemtype => $itemtype_ko->itemtype, + rule_name => 'reservesallowed', + rule_value => '0', + } + ); + C4::Reserves::AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + } + ); + + { + my ($status) = C4::Reserves::CheckReserves($item_ko); + is( $status, '', 'No reserves found for the item that cannot be reserved' ); + } + + { + my ($status) = C4::Reserves::CheckReserves($item_ok); + is( $status, 'Reserved', 'A reserve is found for the item that can be reserved' ); + } + + $schema->txn_rollback; +}; -- 2.39.2