Bug 25297: Consistent return value in K::A::Order->current_item_level_holds
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Apr 2020 21:55:59 +0000 (18:55 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 1 May 2020 07:16:38 +0000 (08:16 +0100)
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 <tomascohen@theke.io>
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Acquisition/Order.pm

index 0d59f59..5135a33 100644 (file)
@@ -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<Koha::Holds>
-resultset in scalar context or a list of I<Koha::Hold> objects in list context.
-
-It returns B<undef> if no I<biblio> or no I<items> 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(
         {