LP#978095 Fixed SQL query
authorLiam Whalen <liam.whalen@bc.libraries.coop>
Thu, 5 Nov 2015 19:33:17 +0000 (11:33 -0800)
committerLiam Whalen <liam.whalen@bc.libraries.coop>
Thu, 5 Nov 2015 19:33:17 +0000 (11:33 -0800)
The SQL query was not gathering the correct data from the
acq.lineitem_detail and acq.lineitem tables.  We needed to add
acq.cancel_reason to the query and test for the presence of no cancel
reasons or the presence of cancel reasons with
acq.cancel_reason.fund_debits of true because we do not want to mark a
lineitem as canceled if it has a cancel reason with fund_debits on it.

Signed-off-by: Liam Whalen <liam.whalen@bc.libraries.coop>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index e779c69..2a85b18 100644 (file)
@@ -3333,20 +3333,42 @@ sub cancel_lineitem_detail {
     $mgr->editor->update_acq_lineitem_detail($lid) or return 0;
 
     my $query = { "select" => { 
-                    "acqlid" => [ 
-                        "lineitem", { 
-                            "column" => "lineitem", 
-                            "transform" => "count", 
-                            "alias" => "lineitem_count", 
-                            "aggregate" => "true" 
-                        }] 
-                    }, 
-                    "from" => { "jub" => "acqlid" }, 
-                    "where" => [{
-                        "+acqlid" => { "lineitem" => $lid->lineitem->id, "cancel_reason" => null }
-                        }, 
-                        {"purchase_order" => $lid->lineitem->purchase_order} 
-                     ]};
+            "acqlid" => [ 
+                "lineitem", { 
+                    "column" => "lineitem", 
+                    "transform" => "count", 
+                    "alias" => "lineitem_count", 
+                    "aggregate" => "true" 
+                }] 
+            }, 
+            "from" => { 
+                "jub" => { 
+                    "acqlid" => { 
+                        "join" => { "acqcr" => {} }
+                    }
+                }
+            }, 
+            "where" => [{
+                    "+acqlid" => { 
+                        "lineitem" => $lid->lineitem->id, 
+                        "cancel_reason" => null 
+                    }
+                }, {
+                    "purchase_order" => $lid->lineitem->purchase_order
+                }, {
+                    "-or" => [{
+                            "+acqlid" => { 
+                                "lineitem" => $lid->lineitem->id, 
+                                "cancel_reason" => { "!=" => null }
+                            }
+                        }, {
+                            "+acqcr" => "keep_debits"
+                        }, {
+                            "purchase_order" => $lid->lineitem->purchase_order
+                        }]
+                }
+            ]};
+    
     my $lineitem_query = $e->json_query($query);
 
     if ($lineitem_query->lineitem_count == 0) {