From 889853bc9d7fca6bea567181b161988528ddf0c2 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 3 Nov 2022 20:50:33 +0000 Subject: [PATCH] Bug 31692: (follow-up) Adjust reserves.item_level_hold Original patch missed handling reserves.item_level_hold column. To test: 1. prove t/db_dependent/Koha/Hold.t Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Hold.pm | 5 ++++- t/db_dependent/Koha/Hold.t | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index e3e8880fa6..2c30f915b3 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -877,7 +877,10 @@ sub change_type { } if ( $record_holds_per_patron->count == 1 ) { - $self->set({ itemnumber => $itemnumber ? $itemnumber : undef })->store; + $self->set({ + itemnumber => $itemnumber ? $itemnumber : undef, + item_level_hold => $itemnumber ? 1 : 0, + })->store; } else { Koha::Exceptions::Hold::CannotChangeHoldType->throw(); } diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index f7741bf20c..563af986c9 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -1000,7 +1000,7 @@ subtest 'Koha::Hold::item_group tests' => sub { subtest 'change_type tests' => sub { - plan tests => 9; + plan tests => 13; $schema->storage->txn_begin; @@ -1009,6 +1009,7 @@ subtest 'change_type tests' => sub { class => 'Koha::Holds', value => { itemnumber => undef, + item_level_hold => 0, } } ); @@ -1025,24 +1026,32 @@ subtest 'change_type tests' => sub { is( $hold->itemnumber, undef, 'record hold to record hold, no changes'); + is( $hold->item_level_hold, 0, 'item_level_hold=0' ); + ok( $hold->change_type( $item->itemnumber ) ); $hold->discard_changes; is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold'); + is( $hold->item_level_hold, 1, 'item_level_hold=1' ); + ok( $hold->change_type( $item->itemnumber ) ); $hold->discard_changes; is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes'); + is( $hold->item_level_hold, 1, 'item_level_hold=1' ); + ok( $hold->change_type ); $hold->discard_changes; is( $hold->itemnumber, undef, 'item hold to record hold'); + is( $hold->item_level_hold, 0, 'item_level_hold=0' ); + my $hold3 = $builder->build_object( { class => 'Koha::Holds', value => { -- 2.39.5