LP#1942220: format fund labels correctly in the batch copy form
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 7 Dec 2021 21:51:09 +0000 (16:51 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 7 Dec 2021 23:43:44 +0000 (18:43 -0500)
While caching the selected funds is good to reduce unnecessary
pcrud queries, doing so breaks formatting the fund label
in the comboboxes consistently without this patch.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/copy-attrs.component.ts

index 4c12012..d6b5aaa 100644 (file)
@@ -4,6 +4,7 @@ import {Pager} from '@eg/share/util/pager';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
+import {OrgService} from '@eg/core/org.service';
 import {LineitemService, COPY_ORDER_DISPOSITION} from './lineitem.service';
 import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
 import {ItemLocationService} from '@eg/share/item-location-select/item-location-select.service';
@@ -62,6 +63,7 @@ export class LineitemCopyAttrsComponent implements OnInit {
         private idl: IdlService,
         private net: NetService,
         private auth: AuthService,
+        private org: OrgService,
         private loc: ItemLocationService,
         private liService: LineitemService
     ) {}
@@ -127,13 +129,31 @@ export class LineitemCopyAttrsComponent implements OnInit {
         }
     }
 
+    // copied from combobox to get the label right for funds
+    getOrgShortname(ou: any) {
+        if (typeof ou === 'object') {
+            return ou.shortname();
+        } else {
+            return this.org.get(ou).shortname();
+        }
+    }
+
     // Tell our inputs about the values we know we need
     // Values will be pre-cached in the liService
+    //
+    // TODO: figure out a better way to do this so that we
+    //       don't need to duplicate the code to format
+    //       the display labels for funds correctly
     setInitialOptions(copy: IdlObject) {
 
         if (copy.fund()) {
             const fund = this.liService.fundCache[copy.fund()];
-            this.fundEntries = [{id: fund.id(), label: fund.code(), fm: fund}];
+            this.fundEntries = [{
+                id: fund.id(),
+                label: fund.code() + ' (' + fund.year() + ')' +
+                       ' (' + this.getOrgShortname(fund.org()) + ')',
+                 fm: fund
+            }];
         }
 
         if (copy.circ_modifier()) {