Control PO activation for zero-copy lineitems
authorBill Erickson <berick@esilibrary.com>
Tue, 10 Jul 2012 15:56:05 +0000 (11:56 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 24 Jul 2012 14:28:30 +0000 (10:28 -0400)
By default, prevent activation of POs when any lineitems are present
that have no copies attached.  This adds a new option in the PO UI
called "Allow activation with zero-copy lineitems", which will allow the
activation to continue even when zero-copy lineitems exist.

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

index ec94c04..8116ca3 100644 (file)
@@ -760,7 +760,8 @@ sub set_lineitem_attr {
 # Lineitem Debits
 # ----------------------------------------------------------------------------
 sub create_lineitem_debits {
-    my ($mgr, $li, $dry_run) = @_; 
+    my ($mgr, $li, $dry_run, $options) = @_; 
+    $options ||= {};
 
     unless($li->estimated_unit_price) {
         $mgr->editor->event(OpenILS::Event->new('ACQ_LINEITEM_NO_PRICE', payload => $li->id));
@@ -779,6 +780,12 @@ sub create_lineitem_debits {
         {idlist=>1}
     );
 
+    if (@$lid_ids == 0 and !$options->{zero_copy_activate}) {
+        $mgr->editor->event(OpenILS::Event->new('ACQ_LINEITEM_NO_COPIES', payload => $li->id));
+        $mgr->editor->rollback;
+        return 0;
+    }
+
     for my $lid_id (@$lid_ids) {
 
         my $lid = $mgr->editor->retrieve_acq_lineitem_detail([
@@ -2305,13 +2312,14 @@ __PACKAGE__->register_method(
 );
 
 sub activate_purchase_order {
-    my($self, $conn, $auth, $po_id, $vandelay) = @_;
+    my($self, $conn, $auth, $po_id, $vandelay, $options) = @_;
+    $options ||= {};
 
     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);
+    my $die_event = activate_purchase_order_impl($mgr, $po_id, $vandelay, $dry_run, $options);
     return $e->die_event if $die_event;
     $conn->respond_complete(1);
     $mgr->run_post_response_hooks unless $dry_run;
@@ -2320,7 +2328,7 @@ sub activate_purchase_order {
 
 # xacts managed within
 sub activate_purchase_order_impl {
-    my ($mgr, $po_id, $vandelay, $dry_run) = @_;
+    my ($mgr, $po_id, $vandelay, $dry_run, $options) = @_;
 
     # read-only until lineitem asset creation
     my $e = $mgr->editor;
@@ -2366,7 +2374,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) or return $e->die_event;
+        create_lineitem_debits($mgr, $li, $dry_run, $options) 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 ec2c9ea..605ad7a 100644 (file)
                     </td>
                 </tr>
                 <tr>
+                    <th></th>
+                    <td></td>
+                    <th>[% l('Allow activation with <br/> zero-copy lineitems') %]</th>
+                    <td><input type='checkbox' id='acq-po-activate-zero-copies' onclick='checkCouldActivatePo()'/></td>
+                <tr>
                     <td colspan='3'>
                         <a class="hidden" id="acq-po-split" href="javascript:void(0);"
                             onclick="if (confirm(localeStrings.CONFIRM_SPLIT_PO)) splitPo();">
index ed4d55e..626e5ce 100644 (file)
@@ -446,7 +446,12 @@ function checkCouldActivatePo() {
 
     fieldmapper.standardRequest(
         ["open-ils.acq", "open-ils.acq.purchase_order.activate.dry_run"], {
-            "params": [openils.User.authtoken, PO.id()],
+            "params": [
+                openils.User.authtoken,
+                PO.id(),
+                null,  // vandelay options
+                {zero_copy_activate : dojo.byId('acq-po-activate-zero-copies').checked}
+            ],
             "async": true,
             "onresponse": function(r) {
                 if ((r = openils.Util.readResponse(r, true /* eventOk */))) {
@@ -523,7 +528,12 @@ function activatePoStage2() {
     fieldmapper.standardRequest(
         ["open-ils.acq", "open-ils.acq.purchase_order.activate"], {
             "async": true,
-            "params": [openils.User.authtoken, PO.id()],
+            "params": [
+                openils.User.authtoken,
+                PO.id(),
+                null,  // vandelay options
+                {zero_copy_activate : dojo.byId('acq-po-activate-zero-copies').checked}
+            ],
             "onresponse": function(r) {
                 want_refresh = Boolean(openils.Util.readResponse(r));
             },