From ac99730d6799bf2d49ed301d016596b9ffa2ca8d Mon Sep 17 00:00:00 2001 From: Liam Whalen Date: Fri, 6 Nov 2015 07:17:06 -0800 Subject: [PATCH] LP#978095 Moved line item cancel code to new sub The line item cancel code when there are no line item details needs a valid $e object. However, there was no $e object in the sub where this code currently exists. So, I moved the code to its own sub and passed in a valid $e object to the new sub. Signed-off-by: Liam Whalen --- .../perlmods/lib/OpenILS/Application/Acq/Order.pm | 98 +++++++++++++--------- 1 file changed, 60 insertions(+), 38 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 2a85b18ec2..051637ffce 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -3257,6 +3257,8 @@ sub cancel_lineitem_detail_api { my $result = cancel_lineitem_detail($mgr, $lid_id, $cancel_reason) or return $e->die_event; + no_lid_cancel_lineitem($e, $lid_id); + if (not_cancelable($result)) { $e->rollback; return $result; @@ -3332,50 +3334,70 @@ sub cancel_lineitem_detail { # update these on the LI when we alter an LID? $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" => { - "join" => { "acqcr" => {} } - } + return {"lid" => {$lid_id => {"cancel_reason" => $cancel_reason}}}; +} + +sub no_lid_cancel_lineitem { + my ($e, $lid_id) = @_; + my $lid = $mgr->editor->retrieve_acq_lineitem_detail([ + $lid_id, { + "flesh" => 2, + "flesh_fields" => { + "acqlid" => ["lineitem","cancel_reason"], + "jub" => ["purchase_order"] + } + } + ]) or return 0; + + #Get a count of lineitem details that exist on the lineitem + #that are not cancelled, or lineitem details that are + #cancelled but having keep_debits = true. + my $query = { "select" => { + "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 - }] + } + }, + "where" => [{ + "+acqlid" => { + "lineitem" => $lid->lineitem->id, + "cancel_reason" => null } - ]}; - - my $lineitem_query = $e->json_query($query); + }, { + "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) + or return 0; if ($lineitem_query->lineitem_count == 0) { - cancel_lineitem_api($lid->lineitem->id, "Canceled: No Copies"); + return cancel_lineitem_api($lid->lineitem->id, "Canceled: No Copies"); } - return {"lid" => {$lid_id => {"cancel_reason" => $cancel_reason}}}; + return 0; } __PACKAGE__->register_method( -- 2.11.0