From 913a1003eb93d76141e0f228b08f15fd745c98ad Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Jan 2023 15:20:04 +0100 Subject: [PATCH] Bug 32528: Change return logic Back to 1 return statement Prevent the Koha::Result::Boolean instanciation duplication --- Koha/Item.pm | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index b17f97bb32e..dae9df8f295 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -289,22 +289,24 @@ returns 1 if the item is safe to delete, sub safe_to_delete { my ($self) = @_; - return Koha::Result::Boolean->new(0)->add_message({ message => "book_on_loan" }) - if $self->checkout; + my $error; - return Koha::Result::Boolean->new(0)->add_message({ message => "not_same_branch" }) + $error = "book_on_loan" if $self->checkout; + + $error //= "not_same_branch" if defined C4::Context->userenv - and !C4::Context->IsSuperLibrarian() - and C4::Context->preference("IndependentBranches") - and ( C4::Context->userenv->{branch} ne $self->homebranch ); + && !C4::Context->IsSuperLibrarian() + && C4::Context->preference("IndependentBranches") + && ( C4::Context->userenv->{branch} ne $self->homebranch ); - return Koha::Result::Boolean->new(0)->add_message({ message => "book_reserved" }) + # check it doesn't have a waiting reserve + $error //= "book_reserved" if $self->holds->filter_by_found->count; - return Koha::Result::Boolean->new(0)->add_message({ message => "linked_analytics" }) + $error //= "linked_analytics" if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0; - return Koha::Result::Boolean->new(0)->add_message({ message => "last_item_for_hold" }) + $error //= "last_item_for_hold" if $self->biblio->items->count == 1 && $self->biblio->holds->search( { @@ -312,6 +314,10 @@ sub safe_to_delete { } )->count; + if ( $error ) { + return Koha::Result::Boolean->new(0)->add_message({ message => $error }); + } + return Koha::Result::Boolean->new(1); } -- 2.25.1