From: Jason Etheridge Date: Fri, 2 Feb 2018 16:30:36 +0000 (-0500) Subject: lp978095 auto-canceling lineitems X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=848484c3171a53a173b86af404de1658e69153a3;p=evergreen%2Fjoelewis.git lp978095 auto-canceling lineitems "Acq: lineitems display as "on order" even after all copies have been cancelled" When a copy (lineitem detail) on a lineitem is canceled through the UI, all of the sibling copies are examined, and if they also happen to be canceled, then a cancel attempt is made on the parent lineitem. The cancel reason fed to the lineitem cancelation attempt will be the last cancel reason on an examined sibling lineitem where Keep Debits is True, or failing that, the cancel reason used wih the copy just canceled. The UI will refresh to the lineitem view when such an auto-cancelation happens. Signed-off-by: Jason Etheridge Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- 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 3eae8602e3..7215e05f3b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -3253,6 +3253,38 @@ sub cancel_lineitem { 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", @@ -3294,6 +3326,10 @@ sub 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? diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 7c19fef1cf..40347fc849 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -2663,6 +2663,9 @@ function AcqLiTable() { r.lid[id].cancel_reason ); self.updateLidState(self.copyCache[id]); + if (r.li_update_needed) { + location.href = location.href; // sledgehammer + } } } } diff --git a/docs/RELEASE_NOTES_NEXT/Acquisitions/autocancel_lineitems_when_all_copies_are_canceled.adoc b/docs/RELEASE_NOTES_NEXT/Acquisitions/autocancel_lineitems_when_all_copies_are_canceled.adoc new file mode 100644 index 0000000000..e84e519cc0 --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/Acquisitions/autocancel_lineitems_when_all_copies_are_canceled.adoc @@ -0,0 +1,3 @@ +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.