From 01596aba0293caeb45f9ccb7b17bfcae65536b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Wed, 22 Jul 2020 15:44:31 +0000 Subject: [PATCH] Bug 12556: Refactor hold transfer status setting to its own method --- C4/Reserves.pm | 6 ++++-- Koha/Hold.pm | 21 +++++++++++++++------ t/db_dependent/Hold.t | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 979b3de244..c6224c702b 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1153,9 +1153,9 @@ sub ModReserveAffect { my $already_on_shelf = $hold->found && $hold->found eq 'W'; $hold->itemnumber($itemnumber); - $hold->set_waiting($transferToDo); if( !$transferToDo ){ + $hold->set_waiting(); _koha_notify_reserve( $hold->reserve_id ) unless $already_on_shelf; my $transfers = Koha::Item::Transfers->search({ itemnumber => $itemnumber, @@ -1164,7 +1164,9 @@ sub ModReserveAffect { while( my $transfer = $transfers->next ){ $transfer->datearrived( dt_from_string() )->store; }; - } + } else { + $hold->set_transfer(); + } _FixPriority( { biblionumber => $biblionumber } ); diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 8969e32839..4c57b7cb2f 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -151,20 +151,29 @@ sub delete { return $deleted; } +=head3 set_transfer + +=cut + +sub set_transfer { + my ( $self ) = @_; + + $self->priority(0); + $self->found('T'); + $self->store(); + + return $self; +} + =head3 set_waiting =cut sub set_waiting { - my ( $self, $transferToDo ) = @_; + my ( $self ) = @_; $self->priority(0); - if ($transferToDo) { - $self->found('T')->store(); - return $self; - } - my $today = dt_from_string(); my $values = { found => 'W', diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index dc588ded2b..d58b0a243c 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -224,7 +224,7 @@ subtest 'suspend() tests' => sub { is( $@->status, 'W', 'Exception gets the \'status\' parameter set correctly' ); # set hold found=T - $hold->set_waiting(1); + $hold->set_transfer; throws_ok { $hold->suspend_hold; } 'Koha::Exceptions::Hold::CannotSuspendFound', -- 2.11.0