Bug 14598: Make C4::Circulation::AddReturn store the right itemtype
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Jul 2015 14:40:38 +0000 (11:40 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 28 Oct 2016 11:29:57 +0000 (11:29 +0000)
This patch makes C4::Circulation::AddReturn correctly store the itemtype
on the 'statistics' table.

To reproduce:
- Checkout master.
- Make a checkout.
- Check the 'statistics' table and notice the itemtype is correctly set
  > SELECT * FROM statistics;
- Check the item in.
- Check the 'statistics' table and notice the itemtype is not set
  > SELECT * FROM statistics WHERE type="return";
=> FAIL: itemtype is set to NULL

To test:
- Apply the regression tests patch
- Run the tests:
  $ prove t/db_dependent/Circulation/Returns.t
=> FAIL: Tests fail
- Apply this patch
- Run the regression tests:
  $ prove t/db_dependent/Circulation/Returns.t
=> SUCCESS: Tests now pass.
- Repeat the 'To reproduce' steps
=> SUCCESS: itemtype is now correctly set (in real life)
- Happily sign off :-D

Sponsored-by: Universidad Empresarial Siglo 21
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Circulation.pm

index cfe3442..fb34b53 100644 (file)
@@ -1844,13 +1844,19 @@ sub AddReturn {
     $branch = C4::Context->userenv->{'branch'} unless $branch;  # we trust userenv to be a safe fallback/default
     my $messages;
     my $borrower;
-    my $biblio;
     my $doreturn       = 1;
     my $validTransfert = 0;
     my $stat_type = 'return';
 
     # get information on item
-    my $itemnumber = GetItemnumberFromBarcode( $barcode );
+    my $item       = GetItem( undef, $barcode )
+        or die "GetItem( undef, $barcode ) failed";
+    my $itemnumber = $item->{ itemnumber };
+    my $biblio = GetBiblioData( $item->{ biblionumber } );
+    my $itemtype   = ( C4::Context->preference("item-level_itypes") )
+                        ? $item->{ itype }
+                        : $biblio->{ itemtype };
+
     unless ($itemnumber) {
         return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
     }
@@ -1871,8 +1877,6 @@ sub AddReturn {
         }
     }
 
-    my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed";
-
     if ( $item->{'location'} eq 'PROC' ) {
         if ( C4::Context->preference("InProcessingToShelvingCart") ) {
             $item->{'location'} = 'CART';
@@ -2073,15 +2077,14 @@ sub AddReturn {
     }
 
     # Record the fact that this book was returned.
-    # FIXME itemtype should record item level type, not bibliolevel type
     UpdateStats({
-                branch => $branch,
-                type => $stat_type,
-                itemnumber => $item->{'itemnumber'},
-                itemtype => $biblio->{'itemtype'},
-                borrowernumber => $borrowernumber,
-                ccode => $item->{'ccode'}}
-    );
+        branch         => $branch,
+        type           => $stat_type,
+        itemnumber     => $itemnumber,
+        itemtype       => $itemtype,
+        borrowernumber => $borrowernumber,
+        ccode          => $item->{ ccode }
+    });
 
     # Send a check-in slip. # NOTE: borrower may be undef.  probably shouldn't try to send messages then.
     my $circulation_alert = 'C4::ItemCirculationAlertPreference';