Show zero-copy lineitem's in zero-copy activation warning acq-po-prevent-activate-sans-copies-rebase
authorBill Erickson <berick@esilibrary.com>
Tue, 10 Jul 2012 20:29:39 +0000 (16:29 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 11 Jul 2012 13:25:49 +0000 (09:25 -0400)
When PO activation fails as a result of zero-copy lineitems, show the
IDs of the zero-copy lineitems along with the failure message.

This adds a new API call

open-ils.acq.purchase_order.no_copy_lineitems.id_list(auth, po_id)

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
Open-ILS/web/js/ui/default/acq/po/view_po.js

index 8116ca3..6e4711e 100644 (file)
@@ -3390,5 +3390,44 @@ sub add_li_to_po {
     return {success => 1};
 }
 
+__PACKAGE__->register_method(
+    method => 'po_lineitems_no_copies',
+    api_name => 'open-ils.acq.purchase_order.no_copy_lineitems.id_list',
+    stream => 1,
+    authoritative => 1, 
+    signature => {
+        desc => q/Returns the set of lineitem IDs for a given PO that have no copies attached/,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'The purchase order id', type => 'number'},
+        ],
+        return => {desc => 'Stream of lineitem IDs on success, event on error'}
+    }
+);
+
+sub po_lineitems_no_copies {
+    my ($self, $conn, $auth, $po_id) = @_;
+
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
+
+    # first check the view perms for LI's attached to this PO
+    my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->event;
+    return $e->event unless $e->allowed('VIEW_PURCHASE_ORDER', $po->ordering_agency);
+
+    my $ids = $e->json_query({
+        select => {jub => ['id']},
+        from => {jub => {acqlid => {type => 'left'}}},
+        where => {
+            '+jub' => {purchase_order => $po_id},
+            '+acqlid' => {lineitem => undef}
+        }
+    });
+
+    $conn->respond($_->{id}) for @$ids;
+    return undef;
+}
+
+
 1;
 
index 626e5ce..53acfa4 100644 (file)
@@ -481,6 +481,21 @@ function checkCouldActivatePo() {
                         d.innerHTML = localeStrings.NO + ": " +
                             other[0].desc + " (" + other[0].textcode + ")";
                         openils.Util.hide(a);
+                        
+                        if (other[0].textcode == 'ACQ_LINEITEM_NO_COPIES') {
+                            // when LIs w/ zero LIDs are present, list them
+                            fieldmapper.standardRequest(
+                                [   'open-ils.acq', 
+                                    'open-ils.acq.purchase_order.no_copy_lineitems.id_list.authoritative.atomic' ],
+                                {   async : true, 
+                                    params : [openils.User.authtoken, poId],
+                                    oncomplete : function(r) {
+                                        var ids = openils.Util.readResponse(r);
+                                        d.innerHTML += ' (' + ids + ')';
+                                    }
+                                }
+                            );
+                        }
                     } else if (stops.length) {
                         d.innerHTML =
                             dojo.string.substitute(