Bug 11170: (follow-up) improve a bit of unnecessarily convoluted logic
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 11 Mar 2014 08:54:55 +0000 (09:54 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 11 Mar 2014 15:11:00 +0000 (15:11 +0000)
This patch also adds POD and UT for the change in SearchOrders()

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Acquisition.pm
t/db_dependent/Acquisition.t

index 5b59519..7d493c9 100644 (file)
@@ -1630,12 +1630,14 @@ sub CancelReceipt {
     basketno => $basketno,
     owner => $owner,
     pending => $pending
+    ordered => $ordered
 });
 
 Searches for orders.
 
 C<$owner> Finds order for the logged in user.
 C<$pending> Finds pending orders. Ignores completed and cancelled orders.
+C<$ordered> Finds orders to receive only (status 'ordered' or 'partial').
 
 
 C<@results> is an array of references-to-hash with the keys are fields
@@ -1681,12 +1683,10 @@ sub SearchOrders {
         WHERE (datecancellationprinted is NULL)
     };
 
-    if ( $pending ) {
+    if ( $pending or $ordered ) {
         $query .= q{ AND (quantity > quantityreceived OR quantityreceived is NULL)};
     }
     if ( $ordered ) {
-        $query .= q{ AND (quantity > quantityreceived OR quantityreceived is NULL)}
-            unless $pending;
         $query .= q{ AND aqorders.orderstatus IN ( "ordered", "partial" )};
     }
 
index 87f0f0f..e78b39c 100755 (executable)
@@ -8,7 +8,7 @@ use POSIX qw(strftime);
 
 use C4::Bookseller qw( GetBookSellerFromId );
 
-use Test::More tests => 64;
+use Test::More tests => 66;
 
 BEGIN {
     use_ok('C4::Acquisition');
@@ -700,6 +700,15 @@ ok(
     "SearchOrders with pending params gets only pending orders (bug 10723)"
 );
 
+$search_orders = SearchOrders({
+    booksellerid => $booksellerid,
+    basketno     => $basketno,
+    pending      => 1,
+    ordered      => 1,
+});
+is( scalar (@$search_orders), 0, "SearchOrders with pending and ordered params gets only pending ordered orders (bug 11170)" );
+
+
 #
 # Test GetBudgetByOrderNumber
 #
@@ -760,6 +769,15 @@ is( join( " ", @$test_extra_fields ),
 is( join( " ", @$test_different_fields ),
     '', "GetLateOrders gets orders with the right content in every fields" );
 
+$search_orders = SearchOrders({
+    booksellerid => $booksellerid,
+    basketno     => $basketno,
+    pending      => 1,
+    ordered      => 1,
+});
+is( scalar (@$search_orders), 3, "SearchOrders with pending and ordered params gets only pending ordered orders. After closing the basket, orders are marked as 'ordered' (bug 11170)" );
+
+
 #
 # Test AddClaim
 #