From: Liam Whalen Date: Thu, 5 Nov 2015 18:34:22 +0000 (-0800) Subject: LP#978095 Cancel lineitem if there are no copies X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5b33f1c56f1a45297080356ad6a1e5c09d0f6e9a;p=working%2FEvergreen.git LP#978095 Cancel lineitem if there are no copies Currently, it is possible to cancel the last copy on a lineitem without also cancelling the lineitem itself. This code cancels the lineitem after the last copy has been canceled. 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 d3a106ebe2..e779c69a3d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -3332,6 +3332,27 @@ 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" }, + "where" => [{ + "+acqlid" => { "lineitem" => $lid->lineitem->id, "cancel_reason" => null } + }, + {"purchase_order" => $lid->lineitem->purchase_order} + ]}; + my $lineitem_query = $e->json_query($query); + + if ($lineitem_query->lineitem_count == 0) { + cancel_lineitem_api($lid->lineitem->id, "Canceled: No Copies"); + } + return {"lid" => {$lid_id => {"cancel_reason" => $cancel_reason}}}; }