Bug 18276: barcode may be nonexistent when checking out/in
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 5 Jul 2017 17:53:57 +0000 (14:53 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 10 Jul 2017 15:22:56 +0000 (12:22 -0300)
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
circ/circulation.pl
circ/returns.pl

index 895d61c..bfe88cf 100755 (executable)
@@ -331,10 +331,13 @@ if (@$barcodes) {
     $template_params->{messages} = $messages;
 
     my $item = Koha::Items->find({ barcode => $barcode });
-    my $biblio = $item->biblio;
+    my ( $biblio, $mss );
 
-    my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.notforloan', authorised_value => { not => undef } });
-    $template_params->{authvalcode_notforloan} = $mss->count ? $mss->next->authorised_value : undef;
+    if ( $item ) {
+        $biblio = $item->biblio;
+        my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.notforloan', authorised_value => { not => undef } });
+        $template_params->{authvalcode_notforloan} = $mss->count ? $mss->next->authorised_value : undef;
+    }
 
     # Fix for bug 7494: optional checkout-time fallback search for a book
 
@@ -412,10 +415,6 @@ if (@$barcodes) {
         );
     }
 
-    $template->param(
-        itembiblionumber => $biblio->biblionumber
-    );
-
 
     # FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue
     $patron = Koha::Patrons->find( $borrowernumber );
@@ -424,6 +423,7 @@ if (@$barcodes) {
     if ( $item ) {
         $template_params->{item} = $item;
         $template_params->{biblio} = $biblio;
+        $template_params->{itembiblionumber} = $biblio->biblionumber;
     }
     push @$checkout_infos, $template_params;
   }
index ddced56..984f030 100755 (executable)
@@ -259,42 +259,44 @@ if ($barcode) {
     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
     my $item = Koha::Items->find({ barcode => $barcode });
 
-    # Check if we should display a checkin message, based on the the item
-    # type of the checked in item
-    my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
-    if ( $itemtype && $itemtype->checkinmsg ) {
-        $template->param(
-            checkinmsg     => $itemtype->checkinmsg,
-            checkinmsgtype => $itemtype->checkinmsgtype,
-        );
-    }
+    if ( $item ) {
+        # Check if we should display a checkin message, based on the the item
+        # type of the checked in item
+        my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
+        if ( $itemtype && $itemtype->checkinmsg ) {
+            $template->param(
+                checkinmsg     => $itemtype->checkinmsg,
+                checkinmsgtype => $itemtype->checkinmsgtype,
+            );
+        }
 
-    # make sure return branch respects home branch circulation rules, default to homebranch
-    my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
-    $returnbranch = $item->$hbr;
+        # make sure return branch respects home branch circulation rules, default to homebranch
+        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
+        $returnbranch = $item->$hbr;
 
-    my $materials = $item->materials;
-    my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
-    $materials = $descriptions->{lib} // $materials;
+        my $materials = $item->materials;
+        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
+        $materials = $descriptions->{lib} // $materials;
 
-    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
+        my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
 
-    my $biblio = $item->biblio;
-    $template->param(
-        title            => $biblio->title,
-        homebranch       => $item->homebranch,
-        holdingbranch    => $item->holdingbranch,
-        returnbranch     => $returnbranch,
-        author           => $biblio->author,
-        itembarcode      => $item->barcode,
-        itemtype         => $item->effective_itemtype,
-        ccode            => $item->ccode,
-        itembiblionumber => $biblio->biblionumber,
-        biblionumber     => $biblio->biblionumber,
-        borrower         => $borrower,
-        additional_materials => $materials,
-        issue            => $issue,
-    );
+        my $biblio = $item->biblio;
+        $template->param(
+            title            => $biblio->title,
+            homebranch       => $item->homebranch,
+            holdingbranch    => $item->holdingbranch,
+            returnbranch     => $returnbranch,
+            author           => $biblio->author,
+            itembarcode      => $item->barcode,
+            itemtype         => $item->effective_itemtype,
+            ccode            => $item->ccode,
+            itembiblionumber => $biblio->biblionumber,
+            biblionumber     => $biblio->biblionumber,
+            borrower         => $borrower,
+            additional_materials => $materials,
+            issue            => $issue,
+        );
+    } # FIXME else we should not call AddReturn but set BadBarcode directly instead
 
     my %input = (
         counter => 0,
@@ -302,6 +304,7 @@ if ($barcode) {
         barcode => $barcode,
     );
 
+
     # do the return
     ( $returned, $messages, $issue, $borrower ) =
       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );