Acq: added UI controls to attach a claim policy to one or many lineitems
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 21 Apr 2010 21:01:55 +0000 (21:01 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 21 Apr 2010 21:01:55 +0000 (21:01 +0000)
Incidentally, two bugs were fixed:
    1) Incorrect permacrud action entries in the IDL that stopped
       open-ils.pcrud from generating methods for the jub and acqlih
       classes.
    2) A widely used acq subroutine, retrieve_lineitem_impl, incorrectly
       cleared the purchase_order and picklist fields of its result if
       fleshing for those fields was not specifically requested. The
       correct behavior is to set those fields back to their integer
       foreign key values. This was causing several subtle problems.

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

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm
Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/templates/default/acq/common/li_table.tt2

index 8066397..9afdd90 100644 (file)
@@ -5464,10 +5464,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="order_summary" reltype="might_have" key="lineitem" map="" class="acqlisum"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
-            <retrieve permission="CREATE_PURCHASE_ORDER VIEW_PURCHASE_ORDER CREATE_PICKLIST VIEW_PICKLIST">
-                <context link="purchase_order" field="ordering_agency"/>
-                <context link="picklist" field="org_unit"/>
-            </retrieve>
+                       <actions>
+                               <retrieve permission="CREATE_PURCHASE_ORDER VIEW_PURCHASE_ORDER CREATE_PICKLIST VIEW_PICKLIST">
+                                       <context link="purchase_order" field="ordering_agency"/>
+                                       <context link="picklist" field="org_unit"/>
+                               </retrieve>
+                       </actions>
                </permacrud>
        </class>
 
@@ -5508,10 +5510,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="claim_policy" reltype="has_a" key="id" map="" class="acqclp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
-            <retrieve permission="CREATE_PURCHASE_ORDER VIEW_PURCHASE_ORDER">
-                <context link="purchase_order" field="ordering_agency"/>
-                <context link="picklist" field="org_unit"/>
-            </retrieve>
+                       <actions>
+                               <retrieve permission="CREATE_PURCHASE_ORDER VIEW_PURCHASE_ORDER">
+                                       <context link="purchase_order" field="ordering_agency"/>
+                                       <context link="picklist" field="org_unit"/>
+                               </retrieve>
+                       </actions>
                </permacrud>
        </class>
 
index 28bf41e..fe5e8b9 100644 (file)
@@ -141,8 +141,14 @@ sub retrieve_lineitem_impl {
                 $li->picklist->org_unit, $li->picklist)
     );
 
-    $li->clear_purchase_order unless $$options{flesh_po};
-    $li->clear_picklist unless $$options{flesh_pl};
+    unless ($$options{flesh_po}) {
+        $li->purchase_order(
+            $li->purchase_order ? $li->purchase_order->id : undef
+        );
+    }
+    unless ($$options{flesh_pl}) {
+        $li->picklist($li->picklist ? $li->picklist->id : undef);
+    }
     return $li;
 }
 
@@ -200,7 +206,7 @@ __PACKAGE__->register_method(
        method => 'update_lineitem',
        api_name        => 'open-ils.acq.lineitem.update',
        signature => {
-        desc => 'Update a lineitem',
+        desc => 'Update one or many lineitems',
         params => [
             {desc => 'Authentication token', type => 'string'},
             {desc => 'lineitem object update', type => 'object'}
@@ -213,8 +219,13 @@ sub update_lineitem {
     my($self, $conn, $auth, $li) = @_;
     my $e = new_editor(xact=>1, authtoken=>$auth);
     return $e->die_event unless $e->checkauth;
-    my $evt = update_lineitem_impl($e, $li);
-    return $evt if $evt;
+
+    $li = [$li] unless ref $li eq "ARRAY";
+    foreach (@$li) {
+        my $evt = update_lineitem_impl($e, $_);
+        return $evt if $evt;
+    }
+
     $e->commit;
     return 1;
 }
@@ -230,8 +241,7 @@ sub update_lineitem_impl {
     ]) or return $e->die_event;
 
     # the marc may have been cleared on retrieval...
-    $li->marc($e->retrieve_acq_lineitem($li->id)->marc)
-        unless $li->marc;
+    $li->marc($orig_li->marc) unless $li->marc;
 
     $li->editor($e->requestor->id);
     $li->edit_time('now');
index d8bebc6..6918435 100644 (file)
@@ -71,5 +71,7 @@
     'NO_FIND_INVOICE': "Could not find that invoice.\nNote that the Invoice # field is case-sensitive.",
     'NO_LI_TO_CLAIM': "You have not selected any lineitems to claim.",
     'CLAIM_VOUCHERS': "Claim Vouchers",
-    'PRINT': "Print"
+    'PRINT': "Print",
+    'ATTACH_CLAIM_POLICY': "Attach claim policy",
+    'CHANGE_CLAIM_POLICY': "Change claim policy"
 }
index 7a9288e..57160bb 100644 (file)
@@ -188,6 +188,42 @@ function AcqLiTable() {
         td.appendChild(document.createTextNode(val));
     };
 
+    this.setClaimPolicyControl = function(li, row) {
+        if (!self.claimPolicyPicker) {
+            self.claimPolicyPicker = true; /* prevents a race condition */
+            new openils.widget.AutoFieldWidget({
+                "parentNode": "acq-lit-li-claim-policy",
+                "fmClass": "acqclp",
+                "selfReference": true,
+                "dijitArgs": {"required": true}
+            }).build(function(w) { self.claimPolicyPicker = w; });
+        }
+
+        if (typeof(row) == "undefined")
+            row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
+
+        var actViewPolicy = nodeByName("action_view_claim_policy", row);
+        if (li.claim_policy())
+            actViewPolicy.innerHTML = localeStrings.CHANGE_CLAIM_POLICY;
+
+        if (!actViewPolicy.onclick) {
+            actViewPolicy.onclick = function() {
+                if (li.claim_policy())
+                    self.claimPolicyPicker.attr("value", li.claim_policy());
+                liClaimPolicyDialog.show();
+                liClaimPolicySave.onClick = function() {
+                    self.changeClaimPolicy(
+                        [li], self.claimPolicyPicker.attr("value"),
+                        function() {
+                            self.setClaimPolicyControl(li, row);
+                            liClaimPolicyDialog.hide();
+                        }
+                    );
+                }
+            };
+        }
+    };
+
     /**
      * Inserts a single lineitem into the growing table of lineitems
      * @param {Object} li The lineitem object to insert
@@ -220,14 +256,7 @@ function AcqLiTable() {
 
         this.updateLiNotesCount(li, row);
 
-        if (li.claim_policy()) {
-            var actViewInvoice = nodeByName("action_view_claim_policy", row);
-            actViewInvoice.disabled = false;
-            actViewInvoice.onclick = function() {
-                location.href = oilsBasePath + "/conify/global/acq/claim_policy/" +
-                    li.claim_policy();
-            };
-        }
+        this.setClaimPolicyControl(li, row);
 
         // show which PO this lineitem is a member of
         if(li.purchase_order() && !this.isPO) {
@@ -1745,9 +1774,43 @@ function AcqLiTable() {
             case "cancel_lineitems":
                 this.maybeCancelLineitems();
                 break;
+
+            case "change_claim_policy":
+                var li_list = this.getSelected();
+                this.claimPolicyPicker.attr("value", null);
+                liClaimPolicyDialog.show();
+                liClaimPolicySave.onClick = function() {
+                    self.changeClaimPolicy(
+                        li_list,
+                        self.claimPolicyPicker.attr("value"),
+                        function() {
+                            li_list.forEach(
+                                function(li) { self.setClaimPolicyControl(li); }
+                            );
+                            liClaimPolicyDialog.hide();
+                        }
+                    )
+                };
+                break;
         }
     }
 
+    this.changeClaimPolicy = function(li_list, value, callback) {
+        li_list.forEach(
+            function(li) { li.claim_policy(value); }
+        );
+        fieldmapper.standardRequest(
+            ["open-ils.acq", "open-ils.acq.lineitem.update"], {
+                "params": [openils.User.authtoken, li_list],
+                "async": true,
+                "oncomplete": function(r) {
+                    r = openils.Util.readResponse(r);
+                    if (callback) callback(r);
+                }
+            }
+        );
+    };
+
     this.createAssets = function() {
         if(!this.isPO) return;
         if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
index a1e9694..de3d0c8 100644 (file)
@@ -24,6 +24,7 @@
                                             <option mask='sr|pl' value='create_order'>Create Purchase Order</option>
                                             <option mask='po' value='create_assets'>Load Bibs and Items</option>
                                             <option mask='po' value='cancel_lineitems'>Cancel Selected Lineitems</option>
+                                            <option mask='po' value='change_claim_policy'>Change Claim Policy</option>
                                             <option mask='po' value='receive_po'>Mark Purchase Order as Received</option>
                                             <option mask='po' value='rollback_receive_po'>Un-Receive Purchase Order</option>
                                             <option mask='po' value='print_po'>Print Purchase Order</option>
@@ -77,7 +78,6 @@
                                     <td style='width:70%;font-weight:bold;'>
                                         <a attr='title' href='javascript:void(0);'></a>
                                         <span name="worksheet">(<a name="worksheet_link" href="javascript:void(0);">&#x270D;</a>)</span>
-                                        <span name="claim_policy" class="hidden">(Claim Policy: <a name="claim_policy_link" href="javascript:void(0);"></a>)</span>
                                         <span name='pl' class='hidden'>(<a name='pl_link' href='javascript:void(0);'></a>)</span>
                                         <span name='po' class='hidden'>(<a name='po_link' href='javascript:void(0);'>PO</a>)</span>
                                     </td>
                             <option name='action_new_invoice' disabled='disabled'>New Invoice</option>
                             <option name='action_link_invoice' disabled='disabled'>Link to Invoice</option>
                             <option name='action_view_invoice' disabled='disabled'>View Invoice(s)</option>
-                            <option name='action_view_claim_policy' disabled='disabled'>View Claim Policy</option>
+                            <option name='action_view_claim_policy'>Apply Claim Policy</option>
                         </select>
                     </td>
                     <td><span name='li_state'></span></td>
             <span dojoType="dijit.form.Button"
                 jsId="acqLidCancelButton">Cancel Copy</span>
         </div>
+        <div dojoType="dijit.Dialog" jsId="liClaimPolicyDialog">
+                <label for="acq-lit-li-claim-policy">Claim policy:</label>
+                <span id="acq-lit-li-claim-policy"></span> &nbsp;
+                <span dojoType="dijit.form.Button"
+                    jsId="liClaimPolicySave">Save</span>
+        </div>
     </div>
 
     <div dojoType="dijit.Dialog" jsId='acqLitChangeLiStateDialog'>