LP#1440114 Remove inv_item via po_item from invoice
authorBill Erickson <berickxx@gmail.com>
Wed, 8 Apr 2015 19:17:01 +0000 (15:17 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 19 Aug 2015 16:33:27 +0000 (12:33 -0400)
Allow invoice_items which were descended from po_item's (direct charges)
to be removed from invoices.  Prior to this, a JS exception prevented
removal of these items.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/acq/invoice/view.js

index d5cf6f1..313e4d7 100644 (file)
@@ -702,11 +702,23 @@ function addInvoiceItem(item) {
 
     nodeByName('delete', row).onclick = function() {
         var cost = widgetRegistry.acqii[item.id()].cost_billed.getFormattedValue();
+
+        var iTypeName = '';
+        if (widgetRegistry.acqii[item.id()].inv_item_type) {
+            iTypeName = widgetRegistry.acqii[item.id()]
+                .inv_item_type.getFormattedValue()
+        } else {
+            // if the invoice_item came from a po_item, the type is
+            // read-only, hence no widget in the registry.  Look up
+            // the name in the cached types list.
+            var itype = itemTypes.filter(
+                function(t) { return (t.code() == item.inv_item_type()) })[0];
+            iTypeName = itype.name();
+        }
+
         var msg = dojo.string.substitute(
-            localeStrings.INVOICE_CONFIRM_ITEM_DELETE, [
-                cost || 0,
-                widgetRegistry.acqii[item.id()].inv_item_type.getFormattedValue() || ''
-            ]
+            localeStrings.INVOICE_CONFIRM_ITEM_DELETE, 
+            [cost || 0, iTypeName || '']
         );
         if(!confirm(msg)) return;
         itemTbody.removeChild(row);