Bug 11552: allow searching on original order number after a transfer
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 14 Jan 2014 12:33:58 +0000 (13:33 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 21 Apr 2014 03:48:31 +0000 (03:48 +0000)
If an order is transferred from one basket to another, it should be
possible to retrieve it with the original order number (AKA order
line).  This patch makes it so.

Test plan:
- transfer an order
- note the original order number and the new one
- receive the order and, on the parcel page, try to find your order with
  the original order number and the new one.

Signed-off-by: sonia bouis <sonia.bouis@univ-lyon3.fr>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
RM note: this works only for the most recent transfer, so if an order
gets transferred multiple times, earlier order numbers won't retrieve
it.

C4/Acquisition.pm
t/db_dependent/Acquisition/TransferOrder.t

index 4bb3c6e..c2e7b3a 100644 (file)
@@ -1747,6 +1747,14 @@ sub SearchOrders {
             LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
             LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
             LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
+    };
+
+    # If we search on ordernumber, we retrieve the transfered order is a transfer has been done.
+    $query .= q{
+            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
+    } if $ordernumber;
+
+    $query .= q{
         WHERE (datecancellationprinted is NULL)
     };
 
@@ -1771,8 +1779,8 @@ sub SearchOrders {
     }
 
     if ( $ordernumber ) {
-        $query .= ' AND (aqorders.ordernumber=?)';
-        push @args, $ordernumber;
+        $query .= ' AND ( aqorders.ordernumber = ? OR aqorders_transfers.ordernumber_from = ? ) ';
+        push @args, ( $ordernumber, $ordernumber );
     }
     if( $search ) {
         $query .= ' AND (biblio.title LIKE ? OR biblio.author LIKE ? OR biblioitems.isbn LIKE ?)';
index a99f455..de9ee4d 100644 (file)
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 8;
+use Test::More tests => 11;
 use C4::Context;
 use C4::Acquisition;
 use C4::Biblio;
@@ -78,6 +78,13 @@ is(scalar GetOrders($basketno2), 1, "1 order in basket2");
 ($order) = GetOrders($basketno2);
 is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 1, "1 item in basket2's order");
 
+# Bug 11552
+my $orders = SearchOrders({ ordernumber => $newordernumber });
+is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with newordernumber' );
+$orders = SearchOrders({ ordernumber => $ordernumber });
+is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with [old]ordernumber' );
+is ( $orders->[0]->{ordernumber}, $newordernumber, 'SearchOrders returns newordernumber if [old]ordernumber is given' );
+
 ModReceiveOrder({
     biblionumber => $biblionumber,
     ordernumber => $newordernumber,