handle deleting line item from selection list more carefully
authorgmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 22 Jan 2011 05:49:10 +0000 (05:49 +0000)
committergmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 22 Jan 2011 05:49:10 +0000 (05:49 +0000)
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 <gmc@esilibrary.com>

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19258 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 85ab54b..c36bf60 100644 (file)
@@ -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});
index 5cea0d5..acb9673 100644 (file)
@@ -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) {