From 100846e48a3923507abc71a16afc67cc6611651d Mon Sep 17 00:00:00 2001 From: gmc Date: Sat, 22 Jan 2011 05:49:10 +0000 Subject: [PATCH] handle deleting line item from selection list more carefully Once a line item is attached to a purchase order, removing it from a selection list should mean detaching it from the list, not deleting it outright. The open-ils.acq.lineitem.delete method can be removed once the old jubgrid code is finally purged. Signed-off-by: Galen Charlton git-svn-id: svn://svn.open-ils.org/ILS/trunk@19258 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Lineitem.pm | 36 ++++++++++++++++++++++ Open-ILS/web/js/ui/default/acq/common/li_table.js | 3 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm index 85ab54b501..c36bf60b1d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm @@ -186,6 +186,32 @@ __PACKAGE__->register_method( } ); +__PACKAGE__->register_method( + method => 'delete_lineitem', + api_name => 'open-ils.acq.purchase_order.lineitem.delete', + signature => { + desc => 'Deletes a lineitem from a purchase order', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'lineitem ID to delete', type => 'number'}, + ], + return => {desc => '1 on success, Event on error'} + } +); + +__PACKAGE__->register_method( + method => 'delete_lineitem', + api_name => 'open-ils.acq.picklist.lineitem.delete', + signature => { + desc => 'Deletes a lineitem from a picklist', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'lineitem ID to delete', type => 'number'}, + ], + return => {desc => '1 on success, Event on error'} + } +); + sub delete_lineitem { my($self, $conn, $auth, $li_id) = @_; my $e = new_editor(xact=>1, authtoken=>$auth); @@ -205,6 +231,16 @@ sub delete_lineitem { # check PO perms } + # once a LI is attached to a PO, deleting it + # from a picklist means *detaching* it from the picklist + if ($self->api_name =~ /picklist/ && $li->purchase_order) { + $li->clear_picklist; + my $evt = update_lineitem_impl($e, $li); + return $evt if $evt; + $e->commit; + return 1; + } + # delete the attached lineitem_details my $lid_ids = $e->search_acq_lineitem_detail( {lineitem => $li_id}, {idlist=>1}); 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 5cea0d5228..acb96734d1 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 @@ -2310,7 +2310,8 @@ function AcqLiTable() { if(idx >= list.length) return; var liId = list[idx].id(); fieldmapper.standardRequest( - ['open-ils.acq', 'open-ils.acq.lineitem.delete'], + ['open-ils.acq', + this.isPO ? 'open-ils.acq.purchase_order.lineitem.delete' : 'open-ils.acq.picklist.lineitem.delete'], { async: true, params: [openils.User.authtoken, liId], oncomplete: function(r) { -- 2.11.0