From 1fcbd77426c29d98e87b93f2c6ebc59e943f25a9 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 | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index b17f97bb32e..6b332733a95 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -289,29 +289,39 @@ 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" }) - if defined C4::Context->userenv - and !C4::Context->IsSuperLibrarian() - and C4::Context->preference("IndependentBranches") - and ( C4::Context->userenv->{branch} ne $self->homebranch ); + $error = "book_on_loan" if $self->checkout; - return Koha::Result::Boolean->new(0)->add_message({ message => "book_reserved" }) - if $self->holds->filter_by_found->count; + $error = "not_same_branch" + if !$error + && defined C4::Context->userenv + && !C4::Context->IsSuperLibrarian() + && C4::Context->preference("IndependentBranches") + && ( C4::Context->userenv->{branch} ne $self->homebranch ); - return Koha::Result::Boolean->new(0)->add_message({ message => "linked_analytics" }) - if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0; + # check it doesn't have a waiting reserve + $error = "book_reserved" + if !$error + && $self->holds->filter_by_found->count; - return Koha::Result::Boolean->new(0)->add_message({ message => "last_item_for_hold" }) - if $self->biblio->items->count == 1 + $error = "linked_analytics" + if !$error + && C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0; + + $error = "last_item_for_hold" + if !$error + && $self->biblio->items->count == 1 && $self->biblio->holds->search( { itemnumber => undef, } )->count; + if ( $error ) { + return Koha::Result::Boolean->new(0)->add_message({ message => $error }); + } + return Koha::Result::Boolean->new(1); } -- 2.25.1