Bug 24356: Make objects.search prefetch embedded relations
[koha-ffzg.git] / circ / returns.pl
index ddce95a..a9e2bc2 100755 (executable)
@@ -589,6 +589,7 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
         my $item = Koha::Items->find({ barcode => $bar_code });
         next unless $item; # FIXME The item has been deleted in the meantime,
                            # we could handle that better displaying a message in the template
+
         my $biblio = $item->biblio;
         # FIXME pass $item to the template and we are done here...
         $ri{itembiblionumber}    = $biblio->biblionumber;
@@ -599,7 +600,8 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
         $ri{itemauthor}          = $biblio->author;
         $ri{itemcallnumber}      = $item->itemcallnumber;
         $ri{dateaccessioned}     = $item->dateaccessioned;
-        $ri{itemtype}            = $item->effective_itemtype;
+        $ri{recordtype}          = $biblio->itemtype;
+        $ri{itemtype}            = $item->itype;
         $ri{itemnote}            = $item->itemnotes;
         $ri{itemnotes_nonpublic} = $item->itemnotes_nonpublic;
         $ri{ccode}               = $item->ccode;
@@ -632,19 +634,21 @@ $template->param(
     AudioAlerts        => C4::Context->preference("AudioAlerts"),
 );
 
-my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
-if ( $item_from_barcode ) {
-    $itemnumber = $item_from_barcode->itemnumber;
-    my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
-    if ( $holdingBranch and $collectionBranch ) {
-        $holdingBranch //= '';
-        $collectionBranch //= $returnbranch;
-        if ( ! ( $holdingBranch eq $collectionBranch ) ) {
-            $template->param(
-              collectionItemNeedsTransferred => 1,
-              collectionBranch => $collectionBranch,
-              itemnumber => $itemnumber,
-            );
+if ( $barcode ) {
+    my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
+    if ( $item_from_barcode ) {
+        $itemnumber = $item_from_barcode->itemnumber;
+        my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
+        if ( $holdingBranch and $collectionBranch ) {
+            $holdingBranch //= '';
+            $collectionBranch //= $returnbranch;
+            if ( ! ( $holdingBranch eq $collectionBranch ) ) {
+                $template->param(
+                  collectionItemNeedsTransferred => 1,
+                  collectionBranch => $collectionBranch,
+                  itemnumber => $itemnumber,
+                );
+            }
         }
     }
 }