Support PO activation w/o loading items user/berick/acq-po-activation-sans-assets-round2
authorBill Erickson <berick@esilibrary.com>
Tue, 27 Nov 2012 20:26:48 +0000 (15:26 -0500)
committerBill Erickson <berick@esilibrary.com>
Tue, 27 Nov 2012 20:26:48 +0000 (15:26 -0500)
Allow for the activation of purchase orders without requiring that bibs
and items be loaded.  (Currently, if bibs and items are not manually
loaded, they are loaded during PO activation).

Adds a new link next to the existing PO Activate link for "Activate
Withoug Loading Items".  Apart from the fact that there are no
underlying bibs/copies, such a PO behaves the same as any other PO.

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

index 7c66162..38cd2a7 100644 (file)
@@ -2410,21 +2410,24 @@ __PACKAGE__->register_method(
 sub activate_purchase_order {
     my($self, $conn, $auth, $po_id, $vandelay, $options) = @_;
     $options ||= {};
+    $$options{dry_run} = ($self->api_name =~ /\.dry_run/) ? 1 : 0;
 
-    my $dry_run = ($self->api_name =~ /\.dry_run/) ? 1 : 0;
     my $e = new_editor(authtoken=>$auth);
     return $e->die_event unless $e->checkauth;
     my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
-    my $die_event = activate_purchase_order_impl($mgr, $po_id, $vandelay, $dry_run, $options);
+    my $die_event = activate_purchase_order_impl($mgr, $po_id, $vandelay, $options);
     return $e->die_event if $die_event;
     $conn->respond_complete(1);
-    $mgr->run_post_response_hooks unless $dry_run;
+    $mgr->run_post_response_hooks unless $$options{dry_run};
     return undef;
 }
 
 # xacts managed within
 sub activate_purchase_order_impl {
-    my ($mgr, $po_id, $vandelay, $dry_run, $options) = @_;
+    my ($mgr, $po_id, $vandelay, $options) = @_;
+    $options ||= {};
+    my $dry_run = $$options{dry_run};
+    my $no_assets = $$options{no_assets};
 
     # read-only until lineitem asset creation
     my $e = $mgr->editor;
@@ -2447,9 +2450,11 @@ sub activate_purchase_order_impl {
 
     my $li_ids = $e->search_acq_lineitem($query, {idlist => 1});
 
-    my $vl_resp; # imported li's and the queue the managing queue
-    if (!$dry_run) {
+    my $vl_resp; # imported li's and the managing queue
+    unless ($dry_run or $no_assets) {
         $e->rollback; # read-only thus far
+
+        # list_assets manages its own transactions
         $vl_resp = create_lineitem_list_assets($mgr, $li_ids, $vandelay)
             or return OpenILS::Event->new('ACQ_LI_IMPORT_FAILED');
         $e->xact_begin;
@@ -2460,7 +2465,7 @@ sub activate_purchase_order_impl {
     for my $li_id (@$li_ids) {
         my $li = $e->retrieve_acq_lineitem($li_id);
         
-        if (!$li->eg_bib_id and !$dry_run) {
+        unless ($li->eg_bib_id or $dry_run or $no_assets) {
             # we encountered a lineitem that was not successfully imported.
             # we cannot continue.  rollback and report.
             $e->rollback;
@@ -2470,7 +2475,7 @@ sub activate_purchase_order_impl {
         $li->state('on-order');
         $li->claim_policy($provider->default_claim_policy)
             if $provider->default_claim_policy and !$li->claim_policy;
-        create_lineitem_debits($mgr, $li, $dry_run, $options) or return $e->die_event;
+        create_lineitem_debits($mgr, $li, $dry_run) or return $e->die_event;
         update_lineitem($mgr, $li) or return $e->die_event;
         $mgr->post_process( sub { create_lineitem_status_events($mgr, $li->id, 'aur.ordered'); });
         $mgr->respond;
index 1baf68a..72b74c1 100644 (file)
                     <th>Activatable?</th>
                     <td>
                         <span id="acq-po-activate-checking"></span>
-                        <a class="hidden" id="acq-po-activate-link" href="javascript:void(0);" onclick="activatePo()">Activate Order</a>
+                        <span class="hidden" id="acq-po-activate-links" style='padding: 5px'>
+                            <a href="javascript:;" onclick="activatePo()">
+                                [% l('Activate Order') %]
+                            </a>
+                            <span style='padding: 5px;'> / </span>
+                            <a href="javascript:;" onclick="activatePo(true)">
+                                [% l('Activate Without Loading Items') %]
+                            </a>
+                        </span>
                     </td>
                 </tr>
                 <tr>
index fd7949f..e9d33ee 100644 (file)
@@ -56,6 +56,7 @@
     "PO_COULD_ACTIVATE" : "Yes.",
     "PO_WARNING_NO_BLOCK_ACTIVATION" : "Yes; fund ${0} (${1}) would be encumbered beyond its warning level.",
     "PO_STOP_BLOCKS_ACTIVATION" : "No; fund ${0} (${1}) would be encumbered beyond its stop level.",
+    "PO_ALREADY_ACTIVATED" : "Activated",
     "PO_FUND_WARNING_CONFIRM" : "Are you sure? Did you see the warning about over-encumbering a fund?",
     "CONFIRM_FUNDS_AT_STOP" : "One or more of the selected funds has a balance below its stop level.\nYou may not be able to activate purchase orders incorporating these copies.\nContinue?",
     "CONFIRM_FUNDS_AT_WARNING" : "One or more of the selected funds has a balance below its warning level.\nContinue?",
index 4c2a7e7..777b39b 100644 (file)
@@ -338,7 +338,11 @@ function renderPo() {
         if (PO.lineitem_count() > 1)
             openils.Util.show("acq-po-split");
     } else {
-        dojo.byId("acq-po-activate-checking").innerHTML = localeStrings.NO;
+        if (PO.order_date()) {
+            dojo.byId("acq-po-activate-checking").innerHTML = localeStrings.PO_ALREADY_ACTIVATED;
+        } else {
+            dojo.byId("acq-po-activate-checking").innerHTML = localeStrings.NO;
+        }
     }
 
     // XXX we probably don't *always* need to do this...
@@ -461,7 +465,7 @@ function init() {
 
 function checkCouldActivatePo() {
     var d = dojo.byId("acq-po-activate-checking");
-    var a = dojo.byId("acq-po-activate-link");
+    var a = dojo.byId("acq-po-activate-links");
     d.innerHTML = localeStrings.PO_CHECKING;
     var warnings = [];
     var stops = [];
@@ -545,7 +549,7 @@ function checkCouldActivatePo() {
     );
 }
 
-function activatePo() {
+function activatePo(noAssets) {
     if (openils.Util.isTrue(PO.prepayment_required())) {
         if (!confirm(localeStrings.PREPAYMENT_REQUIRED_REMINDER))
             return false;
@@ -556,10 +560,15 @@ function activatePo() {
             return false;
     }
 
-    liTable.showAssetCreator(activatePoStage2);
+    if (noAssets) {
+        // no need for AssetCreator when assets are not desired
+        activatePoStage2(true);
+    } else {
+        liTable.showAssetCreator(activatePoStage2);
+    }
 }
 
-function activatePoStage2() {
+function activatePoStage2(noAssets) {
 
     var want_refresh = false;
     progressDialog.show(true);
@@ -570,7 +579,10 @@ function activatePoStage2() {
                 openils.User.authtoken,
                 PO.id(),
                 null,  // vandelay options
-                {zero_copy_activate : dojo.byId('acq-po-activate-zero-copies').checked}
+                {
+                    no_assets : noAssets, // no bibs/volumes/copies required
+                    zero_copy_activate : dojo.byId('acq-po-activate-zero-copies').checked
+                }
             ],
             "onresponse": function(r) {
                 want_refresh = Boolean(openils.Util.readResponse(r));