Bug 18276: (follow-up) Remove GetBiblioFromItemNumber - ILSDI
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 5 May 2017 13:11:02 +0000 (10:11 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 10 Jul 2017 15:22:55 +0000 (12:22 -0300)
Take into account biblio level holds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/ILSDI/Services.pm

index 77ac135..9b65a4a 100644 (file)
@@ -421,26 +421,30 @@ sub GetPatronInfo {
         my $holds = $patron->holds;
         while ( my $hold = $holds->next ) {
 
-            my $unblessed_hold = $hold->unblessed;
+            my ( $item, $biblio, $biblioitem ) = ( {}, {}, {} );
             # Get additional informations
-            my $item = Koha::Items->find( $hold->itemnumber );
-            my $biblio = $item->biblio;
-            my $biblioitem = $biblio->biblioitem;
-            my $library = Koha::Libraries->find( $hold->branchcode ); # Should $hold->get_library
-            my $branchname = $library ? $library->branchname : '';
-
-            # Remove unwanted fields
-            $item = $item->unblessed;
-            delete $item->{'more_subfields_xml'};
-            $biblio = $biblio->unblessed;
-            $biblioitem = $biblioitem->unblessed;
+            if ( $hold->itemnumber ) {    # item level holds
+                $item       = Koha::Items->find( $hold->itemnumber );
+                $biblio     = $item->biblio;
+                $biblioitem = $biblio->biblioitem;
+
+                # Remove unwanted fields
+                $item = $item->unblessed;
+                delete $item->{more_subfields_xml};
+                $biblio     = $biblio->unblessed;
+                $biblioitem = $biblioitem->unblessed;
+            }
 
             # Add additional fields
+            my $unblessed_hold = $hold->unblessed;
             $unblessed_hold->{item}       = { %$item, %$biblio, %$biblioitem };
+            my $library = Koha::Libraries->find( $hold->branchcode );
+            my $branchname = $library ? $library->branchname : '';
             $unblessed_hold->{branchname} = $branchname;
             $unblessed_hold->{title}      = GetBiblio( $hold->biblionumber )->{'title'}; # Should be $hold->get_biblio
 
             push @{ $borrower->{holds}{hold} }, $unblessed_hold;
+
         }
     }