From acc105d7fb2f28bb24faad0314329923c0695124 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 12 Apr 2017 16:54:25 -0400 Subject: [PATCH] LP#1257915 Repair receive-when-cancel query Repaire the json_query used to determine if a PO is ready to be marked received. A PO is non-receiveable if it has any lineitems that are not in the received/cancelled [sic] state OR any that are canceled with a keep_debits=true cancel reason. Prior to this change, simply having a state of "cancelled" was enough to prevent receiving. * Replace tabs w/ spaces * Remove unnecessary "or return 0" clause which was causing Perl precedence warnings. Signed-off-by: Bill Erickson Signed-off-by: Chris Sharp Signed-off-by: Galen Charlton --- .../lib/OpenILS/Application/Acq/Order.pm | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) 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 07aab00d8f..3eae8602e3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -787,7 +787,7 @@ sub receive_lineitem_detail { my $li = check_lineitem_received($mgr, $lid->lineitem) or return 0; return 1 if $li == 1; # li not received - return check_purchase_order_received($mgr, $li->purchase_order) or return 0; + return check_purchase_order_received($mgr, $li->purchase_order); } @@ -1191,21 +1191,29 @@ sub create_purchase_order { sub check_purchase_order_received { my($mgr, $po_id) = @_; - my $non_recv_li = $mgr->editor->json_query({ - "select" =>{ - "jub" =>["id"] - }, - "from" =>{ - "jub" => {"acqcr" => {"type" => "left"}} - }, - "where" =>{ - "+jub" => {"purchase_order" => $po_id}, - "-or" => [ - {"+jub" => {"state" => {"!=" => "received"}}}, - {"+acqcr" => {"keep_debits" =>"t"}} - ] - } - }); + my $non_recv_li = $mgr->editor->json_query({ + "select" =>{ + "jub" =>["id"] + }, + "from" =>{ + "jub" => {"acqcr" => {"type" => "left"}} + }, + "where" => { + "+jub" => {"purchase_order" => $po_id}, + # Return lineitems that are not in the received/cancelled [sic] + # state OR those that are canceled with keep_debits=true. + "-or" => [ + {"+jub" => { + "state" => {"not in" => ["received", "cancelled"]}} + }, { + "-and" => [ + {"+jub" => {"state" => "cancelled"}}, + {"+acqcr" => {"keep_debits" =>"t"}} + ] + } + ] + } + }); my $po = $mgr->editor->retrieve_acq_purchase_order($po_id); return $po if @$non_recv_li; @@ -3240,7 +3248,6 @@ sub cancel_lineitem { # check to see if this cancelation should result in # marking the purchase order "received" - my $po; return 0 unless check_purchase_order_received($mgr, $li->purchase_order->id); return $result; -- 2.43.2