From: Liam Whalen Date: Thu, 5 Nov 2015 19:33:17 +0000 (-0800) Subject: LP#978095 Fixed SQL query X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5277da83513016dad2772144bea7b0fa1a6b1a32;p=working%2FEvergreen.git LP#978095 Fixed SQL query 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 --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm index e779c69a3d..2a85b18ec2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -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) {