From 15595a5f35a204ec26501a9a0fcec2d5a21f0e24 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 27 Apr 2020 18:55:59 -0300 Subject: [PATCH] Bug 25297: Consistent return value in K::A::Order->current_item_level_holds MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch makes the return values for 'current_item_level_holds' consistent: they will always be a Koha::Holds iterator. To test: 1. Apply the regression tests 2. Run: $ kshell k$ prove t/db_dependent/Koha/Acquisition/Order.t => FAIL: It doesn't work as expected, cannot call ->count on undef, etc 3. Apply this patch 4. Repeat 2. => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Frédéric Demians Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- Koha/Acquisition/Order.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 0d59f5989d..5135a3372d 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -25,6 +25,7 @@ use Koha::Acquisition::Invoices; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Biblios; +use Koha::Holds; use Koha::Items; use Koha::Subscriptions; @@ -182,9 +183,7 @@ sub subscription { my $holds = $order->current_item_level_holds; Returns the current item-level holds associated to the order. It returns a I -resultset in scalar context or a list of I objects in list context. - -It returns B if no I or no I are linked to the order. +resultset. =cut @@ -193,11 +192,11 @@ sub current_item_level_holds { my $items_rs = $self->_result->aqorders_items; my @item_numbers = $items_rs->get_column('itemnumber')->all; + my $biblio = $self->biblio; - return unless @item_numbers; - - my $biblio = $self->biblio; - return unless $biblio; + unless ( $biblio and @item_numbers ) { + return Koha::Holds->new->empty; + } return $biblio->current_holds->search( { -- 2.39.5