return $result;
}
+sub autocancel_lineitem {
+ my $mgr = shift;
+ my $lid_id = shift;
+ my $candidate_cancel_reason = shift;
+
+ my $lid = $mgr->editor->search_acq_lineitem_detail({id => $lid_id});
+ my $li_id = $lid->[0]->lineitem;
+
+ my $all_lids = $mgr->editor->search_acq_lineitem_detail([{
+ lineitem => $li_id
+ },{
+ flesh => 1,
+ flesh_fields => { acqlid => ['cancel_reason'] }
+ }]);
+
+ my $all_lids_are_canceled = 1;
+ foreach my $lid ( @{ $all_lids } ) {
+ if (! $lid->cancel_reason ) {
+ $all_lids_are_canceled = 0;
+ }
+ if ($lid->cancel_reason) {
+ if ($U->is_true($lid->cancel_reason->keep_debits)) {
+ $candidate_cancel_reason = $lid->cancel_reason;
+ }
+ }
+ }
+ my $cancel_result;
+ if ($all_lids_are_canceled) {
+ eval { $cancel_result = cancel_lineitem($mgr, $li_id, $candidate_cancel_reason); };
+ }
+ return $cancel_result;
+}
__PACKAGE__->register_method(
method => "cancel_lineitem_detail_api",
return new OpenILS::Event("ACQ_ALREADY_CANCELED");
}
+ if (defined autocancel_lineitem($mgr,$lid_id,$cancel_reason)) {
+ $$result{'li_update_needed'} = 1;
+ }
+
$e->commit or return $e->die_event;
# XXX create lineitem detail status events?
--- /dev/null
+Auto-Cancel Lineitems When All Copies Are Canceled
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+When a copy (lineitem detail) is canceled through the Acquisitions interface, the parent lineitem is also canceled if all copies for that lineitem are also canceled. The cancel reason given will be taken from the last copy with a cancel reason where Keep Debits is true, or failing that, the cancel reason used for the copy just canceled.