Acq: for showing related lineitems, do the right thing w/ null bib rec
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 15 Mar 2010 15:45:02 +0000 (15:45 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 15 Mar 2010 15:45:02 +0000 (15:45 +0000)
Also, flesh_cancel_reason employed in more of the cases where we're retrieving
lineitems to build an li_table, and li_table doesn't fail so hard when it
doesn't have a fleshed cancel_reason.

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

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

index f397570..92c00f2 100644 (file)
@@ -309,23 +309,16 @@ __PACKAGE__->register_method (
 );
 
 sub lineitems_related_by_bib {
-    my($self, $conn, $auth, $id_value, $options) = @_;
+    my($self, $conn, $auth, $test_value, $options) = @_;
     my $e = new_editor(authtoken => $auth);
     return $e->event unless $e->checkauth;
 
     my $perm_orgs = $U->user_has_work_perm_at($e, 'VIEW_PURCHASE_ORDER', {descendants =>1}, $e->requestor->id);
 
-    if ($self->api_name =~ /by_lineitem_id/) {
-        my $orig = retrieve_lineitem($self, $conn, $auth, $id_value) or
-            return $e->die_event;
-        $id_value = $orig->eg_bib_id;
-    }
-
     my $query = {
         "select"=>{"jub"=>["id"]},
         "from"=>{"jub"=>"acqpo"}, 
         "where"=>{
-            "eg_bib_id"=>$id_value,
             "+acqpo"=>{
                 "ordering_agency"=>{
                     "in"=>$perm_orgs
@@ -335,6 +328,22 @@ sub lineitems_related_by_bib {
         "order_by"=>[{"class"=>"jub", "field"=>"create_time", "direction"=>"desc"}]
     };
 
+    # Be sure we just return the original LI if no related bibs
+    if ($self->api_name =~ /by_lineitem_id/) {
+        my $orig = retrieve_lineitem($self, $conn, $auth, $test_value) or
+            return $e->die_event;
+        if ($test_value = $orig->eg_bib_id) {
+            $query->{"where"}->{"eg_bib_id"} = $test_value;
+        } else {
+            $query->{"where"}->{"id"} = $orig->id;
+        }
+    } elsif ($test_value) {
+        $query->{"where"}->{"eg_bib_id"} = $test_value;
+    } else {
+        $e->disconnect;
+        return new OpenILS::Event("BAD_PARAMS", "Null bib id");
+    }
+
     if ($options && defined $options->{lineitem_state}) {
         $query->{'where'}{'jub'}{'state'} = $options->{lineitem_state};
     }
index 7de3936..7c4eb9b 100644 (file)
@@ -288,6 +288,7 @@ __PACKAGE__->register_method(
                 "flesh_attrs", additionaly return the list of flattened attributes
                 "clear_marc", discards the raw MARC data to reduce data size
                 "flesh_notes", flesh lineitem notes
+                "flesh_cancel_reason", flesh cancel_reason
                 /, 
                 type => 'hash'}
         ],
@@ -349,13 +350,14 @@ sub retrieve_pl_lineitem {
 
         my $entry;
         my $flesh = {};
-        if($$options{flesh_attrs} or $$options{flesh_notes}) {
+        if($$options{flesh_attrs} or $$options{flesh_notes} or $$options{flesh_cancel_reason}) {
             $flesh = {flesh => 2, flesh_fields => {jub => []}};
             if($$options{flesh_notes}) {
                 push(@{$flesh->{flesh_fields}->{jub}}, 'lineitem_notes');
                 $flesh->{flesh_fields}->{acqlin} = ['alert_text'];
             }
             push(@{$flesh->{flesh_fields}->{jub}}, 'attributes') if $$options{flesh_attrs};
+            push @{$flesh->{flesh_fields}->{jub}}, 'cancel_reason' if $$options{flesh_cancel_reason};
         }
 
         $entry = $e->retrieve_acq_lineitem([$id, $flesh]);
index 0b3275f..63849f5 100644 (file)
@@ -296,19 +296,23 @@ function AcqLiTable() {
         var state_cell = nodeByName("li_state", row);
 
         if (li.state() == "cancelled") {
-            var holds_state = dojo.create(
-                "span", {
-                    "style": "border-bottom: 1px dashed #000;",
-                    "innerHTML": li.state()
-                }, state_cell, "only"
-            );
-            new dijit.Tooltip(
-                {
-                    "label": "<em>" + li.cancel_reason().label() +
-                        "</em><br />" + li.cancel_reason().description(),
-                    "connectId": [holds_state]
-                }, dojo.create("span", null, state_cell, "last")
-            );
+            if (typeof li.cancel_reason() == "object") {
+                var holds_state = dojo.create(
+                    "span", {
+                        "style": "border-bottom: 1px dashed #000;",
+                        "innerHTML": li.state()
+                    }, state_cell, "only"
+                );
+                new dijit.Tooltip(
+                    {
+                        "label": "<em>" + li.cancel_reason().label() +
+                            "</em><br />" + li.cancel_reason().description(),
+                        "connectId": [holds_state]
+                    }, dojo.create("span", null, state_cell, "last")
+                );
+            } else {
+                state_cell.innerHTML = li.state(); // TODO i18n state labels
+            }
         } else {
             state_cell.innerHTML = li.state(); // TODO i18n state labels
         }
index d46cd00..c6538fe 100644 (file)
@@ -42,7 +42,8 @@ function fetchLi() {
             "params": [openils.User.authtoken, liId, {
                 "flesh_attrs": true,
                 "flesh_li_details": true,
-                "flesh_fund_debit": true
+                "flesh_fund_debit": true,
+                "flesh_cancel_reason": true
             }],
             "oncomplete": function(r) {
                 drawLiInfo(openils.Util.readResponse(r));
@@ -66,7 +67,9 @@ function fetchRelated() {
         ["open-ils.acq", "open-ils.acq.lineitems_for_bib.by_lineitem_id"], {
             "async": true,
             "params": [openils.User.authtoken, liId, {
-                "flesh_attrs": true, "flesh_notes": true
+                "flesh_attrs": true,
+                "flesh_notes": true,
+                "flesh_cancel_reason": true
             }],
             "onresponse": function(r) {
                 var resp = openils.Util.readResponse(r);