From 48788ed161854a87a69d9f9c24bda3f624e63d36 Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 1 Apr 2010 05:15:00 +0000 Subject: [PATCH] Har, I looked in Lineitem.pm for an existing lineitem cancel method before I started, but not Order.pm. Remove the one from Lineitem.pm and tweak the one in Order.pm. Still need smoketest, etc. From my open-ils.acq.lineitem.cancel branch git-svn-id: svn://svn.open-ils.org/ILS/trunk@16077 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Lineitem.pm | 63 ---------------------- .../src/perlmods/OpenILS/Application/Acq/Order.pm | 53 +++++++++++++----- 2 files changed, 40 insertions(+), 76 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm index 1249c5a079..e050fee6d7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm @@ -152,69 +152,6 @@ sub retrieve_lineitem_impl { } __PACKAGE__->register_method( - method => 'cancel_lineitem', - api_name => 'open-ils.acq.lineitem.cancel', - signature => { - desc => 'Cancels a lineitem, any of its detail entries and corresponding copies and call numbers, and potentially related holds (if the bib becomes empty).', - params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'lineitem ID to cancel', type => 'number'}, - ], - return => {desc => '1 on success, Event on error'} - } -); - -sub cancel_lineitem { - my($self, $conn, $auth, $li_id, $cancel_reason) = @_; - my $e = new_editor(xact=>1, authtoken=>$auth); - return $e->die_event unless $e->checkauth; - - $cancel_reason = $e->retrieve_acq_cancel_reason($cancel_reason); - if (!$cancel_reason) { - $e->rollback; - return new OpenILS::Event( - "BAD_PARAMS", - "note" => "Provide cancel reason ID" # let client handle I18N for such events? - ); - } - - my $li = $e->retrieve_acq_lineitem($li_id) - or return $e->die_event; - $li->cancel_reason( $cancel_reason); - - # cancel the attached lineitem_details and gather corresponding copies - my $lids = $e->search_acq_lineitem_detail({ - lineitem => $li_id - }, { - flesh => 1, - flesh_fields => { acqlid => ['eg_copy_id'] } - }); - - my $copies = []; - for my $lid (@$lids) { - $lid->cancel_reason( $cancel_reason ); - $e->update_acq_lineitem_detail( $lid ); - $lid->eg_copy_id->isdeleted('t'); - push @$copies, $lid->eg_copy_id; - } - - # attempt to delete the gathered copies (will this may handle volume deletion and do hold retargeting for us?) - my $cat = OpenSRF::AppSession->create('open-ils.cat'); - $cat->connect; - my $req = $cat->request('open-ils.cat.asset.copy.fleshed.batch.update', $auth, $copies); - my $result = $req->recv; - $cat->disconnect; - if ($result != 1) { # failed to delete copies - $e->rollback; - return $result; - } - - $e->update_acq_lineitem($li) or return $e->die_event; - $e->commit; - return 0; -} - -__PACKAGE__->register_method( method => 'delete_lineitem', api_name => 'open-ils.acq.lineitem.delete', signature => { diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index c0283c4ef4..f755fbbb75 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -2417,23 +2417,35 @@ sub cancel_lineitem { return new OpenILS::Event( "ACQ_NOT_CANCELABLE", "note" => "lineitem $li_id" ) unless ( - $li->purchase_order and ( - $li->state eq "on-order" or $li->state eq "pending-order" + (! $li->purchase_order) or ( + $li->purchase_order and ( + $li->state eq "on-order" or $li->state eq "pending-order" + ) ) ); $li->state("cancelled"); $li->cancel_reason($cancel_reason); - my $lid_ids = $mgr->editor->search_acq_lineitem_detail( - {"lineitem" => $li_id}, {"idlist" => 1} - ); + my $lids = $mgr->editor->search_acq_lineitem_detail({ + "lineitem" => $li_id + }, { + flesh => 1, + flesh_fields => { acqlid => ['eg_copy_id'] } + }); my $result = {"lid" => {}}; - foreach my $lid_id (@$lid_ids) { - my $lid_result = cancel_lineitem_detail($mgr, $lid_id, $cancel_reason) + my $copies = []; + foreach my $lid (@$lids) { + my $lid_result = cancel_lineitem_detail($mgr, $lid->id, $cancel_reason) or return 0; + # gathering any real copies for deletion + if ($lid->eg_copy_id) { + $lid->eg_copy_id->isdeleted('t'); + push @$copies, $lid->eg_copy_id; + } + next if $lid_result == -1; # already canceled: just skip it. return $lid_result if not_cancelable($lid_result); # not cxlable: stop. @@ -2443,6 +2455,18 @@ sub cancel_lineitem { $result->{"lid"}->{$k} = $v; } + # attempt to delete the gathered copies (will this may handle volume deletion and do hold retargeting for us?) + my $cat_service = OpenSRF::AppSession->create('open-ils.cat'); + $cat_service->connect; + my $cat_req = $cat_service->request('open-ils.cat.asset.copy.fleshed.batch.update', $mgr->editor->authtoken, $copies); + my $cat_result = $cat_req->recv; + $cat_service->disconnect; + if ($cat_result != 1) { # failed to delete copies + return new OpenILS::Event( + "ACQ_NOT_CANCELABLE", "note" => "lineitem $li_id", "payload" => $cat_result + ); + } + # TODO delete the associated fund debits? # TODO who/what/where/how do we indicate this change for electronic orders? @@ -2521,18 +2545,21 @@ sub cancel_lineitem_detail { return new OpenILS::Event( "ACQ_NOT_CANCELABLE", "note" => "lineitem_detail $lid_id" ) unless ( - (not $lid->recv_time) and - $lid->lineitem and - $lid->lineitem->purchase_order and ( - $lid->lineitem->state eq "on-order" or - $lid->lineitem->state eq "pending-order" + (! $lid->lineitem->purchase_order) or + ( + (not $lid->recv_time) and + $lid->lineitem and + $lid->lineitem->purchase_order and ( + $lid->lineitem->state eq "on-order" or + $lid->lineitem->state eq "pending-order" + ) ) ); return 0 unless $mgr->editor->allowed( "CREATE_PURCHASE_ORDER", $lid->lineitem->purchase_order->ordering_agency - ); + ) or (! $lid->lineitem->purchase_order); $lid->cancel_reason($cancel_reason); -- 2.11.0