LP#1942220: exclude invalid LIs when creating PO from SL
authorGalen Charlton <gmc@equinoxOLI.org>
Thu, 10 Feb 2022 23:34:38 +0000 (18:34 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Thu, 10 Feb 2022 23:34:38 +0000 (18:34 -0500)
LIs that are not in a valid state to be added to a PO (e.g.,
if they already were) are now excluded when creating a PO
from an SL. This fixes a problem where if a SL had some LIs
that were added to an order, including those LIs when creating
a new PO would cause the PO creation to silently fail.

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

index db6edbf..1912c21 100644 (file)
@@ -1,9 +1,13 @@
 <eg-staff-banner bannerText="Create Purchase Order" i18n-bannerText>
 </eg-staff-banner>
 
-<div class="col-lg-4 offset-lg-4">
-  <div *ngIf="lineitems.length">
+<div class="col-lg-4 offset-lg-4" [hidden]="!initDone">
+  <div *ngIf="lineitems.length || origLiCount">
     <span i18n>Creating for {{lineitems.length}} line items.</span>
+    <span i18n *ngIf="lineitems.length !== origLiCount" class="alert-warning">
+      (There were {{origLiCount}} selected, but not all were in a valid state
+       to be added to a purchase order.)
+    </span>
     <hr class="p-1" />
   </div>
   <div class="form-group">
index 145ac3c..d8b1ae3 100644 (file)
@@ -16,6 +16,12 @@ import {PoService} from './po.service';
 import {LineitemService} from '../lineitem/lineitem.service';
 import {CancelDialogComponent} from '../lineitem/cancel-dialog.component';
 
+const VALID_PRE_PO_LI_STATES = [
+    'new',
+    'selector-ready',
+    'order-ready',
+    'approved'
+];
 
 @Component({
   templateUrl: 'create.component.html',
@@ -25,6 +31,7 @@ export class PoCreateComponent implements OnInit {
 
     initDone = false;
     lineitems: number[] = [];
+    origLiCount = 0;
     poName: string;
     orderAgency: number;
     provider: ComboboxEntry;
@@ -50,13 +57,29 @@ export class PoCreateComponent implements OnInit {
 
         this.route.queryParamMap.subscribe((params: ParamMap) => {
             this.lineitems = params.getAll('li').map(id => Number(id));
+            this.origLiCount = this.lineitems.length;
         });
 
-        this.load().then(_ => this.initDone = true);
+        this.load();
     }
 
-    load(): Promise<any> {
-        return Promise.resolve();
+    load() {
+        if (this.origLiCount > 0) {
+            const fleshed_lis: IdlObject[] = [];
+            this.liService.getFleshedLineitems(this.lineitems, { fromCache: false }).subscribe(
+                liStruct => {
+                    fleshed_lis.push(liStruct.lineitem);
+                },
+                err => { },
+                () => {
+                    this.lineitems = fleshed_lis.filter(li => VALID_PRE_PO_LI_STATES.includes(li.state()))
+                                                .map(li => li.id());
+                    this.initDone = true;
+                }
+            );
+        } else {
+            this.initDone = true;
+        }
     }
 
     orgChange(org: IdlObject) {