No subject
Thu May 28 17:10:26 EDT 2009
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm 2010-04-01 05:14:47 UTC (rev 16076)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm 2010-04-01 05:15:00 UTC (rev 16077)
@@ -152,69 +152,6 @@
}
__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 => {
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-04-01 05:14:47 UTC (rev 16076)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-04-01 05:15:00 UTC (rev 16077)
@@ -2417,23 +2417,35 @@
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 @@
$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 @@
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);
More information about the open-ils-commits
mailing list