From b5006138b336c84815c1fc819b8cecf08c3d031d 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 Signed-off-by: Timothy Alexis Vass --- 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 2422d4facd..4690d97faf 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1161,9 +1161,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, @@ -1172,7 +1172,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 360b43e7b5..845028da97 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -153,20 +153,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