From 4b43c886a0ce030e50c894f941665b7c92d50f00 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Tue, 25 Aug 2020 14:53:55 -0300 Subject: [PATCH] Bug 22789: (follow-up) Fix atomic update, GUI and more than one hold This patch * sets one check for reserves and another for old_reserves in atomic update * Adds a message below the checkbox and adds detail when a hold is non priority * Fixes issue when there are more than one hold, but the first is non priority * Adds test case for this last scenario Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 9 ++- .../data/mysql/atomicupdate/bug_22789.perl | 3 + .../prog/en/includes/holds_table.inc | 57 ++++++++++++------- .../prog/en/modules/reserve/request.tt | 3 +- reserve/request.pl | 1 + t/db_dependent/Holds.t | 26 ++++++++- 6 files changed, 75 insertions(+), 24 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7572bd12cd..3571051e84 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2761,7 +2761,14 @@ sub CanBookBeRenewed { my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); - $resfound = 0 if $resrec->{non_priority}; + # If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. + if ( $resfound && $resrec->{non_priority} ) { + $resfound = Koha::Holds->search( + { biblionumber => $resrec->{biblionumber}, non_priority => 0 } ) + ->count > 0; + } + + # This item can fill one or more unfilled reserve, can those unfilled reserves # all be filled by other available items? diff --git a/installer/data/mysql/atomicupdate/bug_22789.perl b/installer/data/mysql/atomicupdate/bug_22789.perl index 1986b14ba6..eb75263f66 100644 --- a/installer/data/mysql/atomicupdate/bug_22789.perl +++ b/installer/data/mysql/atomicupdate/bug_22789.perl @@ -6,6 +6,9 @@ if( CheckVersion( $DBversion ) ) { # or perform some test and warn if( !column_exists( 'reserves', 'non_priority' ) ) { $dbh->do("ALTER TABLE reserves ADD COLUMN `non_priority` tinyint(1) NOT NULL DEFAULT 0 AFTER `item_level_hold` -- Is this a non priority hold"); + } + + if( !column_exists( 'old_reserves', 'non_priority' ) ) { $dbh->do("ALTER TABLE old_reserves ADD COLUMN `non_priority` tinyint(1) NOT NULL DEFAULT 0 AFTER `item_level_hold` -- Is this a non priority hold"); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index 26791f819d..01dfed3171 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -140,38 +140,53 @@ + [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 820543d509..36ca0a538f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -477,9 +477,10 @@ [% END %] [% END # /UNLESS multi_hold %] -
  • +
  • +
    A non priority hold doesn't prevent a current checkout from renewing
  • diff --git a/reserve/request.pl b/reserve/request.pl index b1e8745969..0bf0bae5d4 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -705,6 +705,7 @@ foreach my $biblionumber (@biblionumbers) { $reserve{'reserve_id'} = $res->reserve_id(); $reserve{itemtype} = $res->itemtype(); $reserve{branchcode} = $res->branchcode(); + $reserve{non_priority} = $res->non_priority(); $reserve{object} = $res; push( @reserveloop, \%reserve ); diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 25793192e3..0cffe1501a 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -1256,7 +1256,7 @@ subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub { subtest 'non priority holds' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; @@ -1323,6 +1323,30 @@ subtest 'non priority holds' => sub { ok( $ok, 'Can renew' ); is( $err, undef, 'Item is on non priority hold' ); + my $patron3 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $item->homebranch } + } + ); + + # Add second hold with non_priority = 0 + AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron3->borrowernumber, + biblionumber => $item->biblionumber, + priority => 2, + itemnumber => $item->itemnumber, + } + ); + + ( $ok, $err ) = + CanBookBeRenewed( $patron1->borrowernumber, $item->itemnumber ); + + ok( !$ok, 'Cannot renew' ); + is( $err, 'on_reserve', 'Item is on hold' ); + $schema->storage->txn_rollback; }; -- 2.39.5