Bug 5336: (follow-up) improve setting 'partial' order status during upgrade
authorGalen Charlton <gmc@esilibrary.com>
Tue, 22 Oct 2013 13:49:32 +0000 (13:49 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 22 Oct 2013 13:49:32 +0000 (13:49 +0000)
This patch modifies the logic to set the partial status for an
order to verify that:

- at least one item has been received already
- the order belongs to a closed basket

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
installer/data/mysql/updatedatabase.pl

index 89ce9f4..b031ed8 100755 (executable)
@@ -7310,7 +7310,20 @@ $DBversion = "3.13.00.032";
 if ( CheckVersion($DBversion) ) {
     $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus varchar(16) DEFAULT 'new' AFTER parent_ordernumber");
     $dbh->do("UPDATE aqorders SET orderstatus='ordered' WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
-    $dbh->do("UPDATE aqorders SET orderstatus='partial' WHERE quantity > quantityreceived AND ordernumber IN ( SELECT parent_ordernumber FROM ( SELECT DISTINCT(parent_ordernumber) FROM aqorders WHERE ordernumber != parent_ordernumber) AS aq )");
+    $dbh->do(q{
+        UPDATE aqorders SET orderstatus='partial'
+        WHERE quantity > quantityreceived
+        AND quantityreceived > 0
+        AND ordernumber IN (
+            SELECT parent_ordernumber
+            FROM (
+                SELECT DISTINCT(parent_ordernumber)
+                FROM aqorders
+                WHERE ordernumber != parent_ordernumber
+            ) AS aq 
+        )
+        AND basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)
+    });
     $dbh->do("UPDATE aqorders SET orderstatus='complete' WHERE quantity=quantityreceived");
     $dbh->do("UPDATE aqorders SET orderstatus='cancelled' WHERE datecancellationprinted IS NOT NULL");
     print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";