LP1929741 Lineitem delete repairs
authorBill Erickson <berickxx@gmail.com>
Mon, 3 May 2021 15:28:09 +0000 (11:28 -0400)
committerJane Sandberg <js7389@princeton.edu>
Sun, 2 Oct 2022 15:02:49 +0000 (08:02 -0700)
Allow deleting lineitems on PO's for certaian states.

Fix lineitem delete code issues.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-list.component.html
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-list.component.ts

index c8588b5..bab495d 100644 (file)
@@ -9,10 +9,10 @@
       <div ngbDropdownMenu>
         <a ngbDropdownItem routerLink="../brief-record"
           queryParamsHandling="merge" i18n>Add Brief Record</a>
+        <button ngbDropdownItem (click)="deleteLineitems()" 
+          [disabled]="!canDeleteLis()" i18n>Delete Selected Lineitems</button>
         <div class="dropdown-divider"></div>
         <h6 class="dropdown-header" i18n>Selection List Actions</h6>
-        <button ngbDropdownItem (click)="deleteLineitems()" 
-          [disabled]="!picklistId" i18n>Delete Selected Lineitems</button>
         <button ngbDropdownItem (click)="createPo()" 
           [disabled]="!picklistId" i18n>Create Purchase Order from Selected Lineitems</button>
         <button ngbDropdownItem (click)="createPo(true)"
index 0bb5b60..e29938f 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, OnInit, Input, Output, ViewChild} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
-import {Observable} from 'rxjs';
-import {tap} from 'rxjs/operators';
+import {Observable, from} from 'rxjs';
+import {tap, concatMap} from 'rxjs/operators';
 import {Pager} from '@eg/share/util/pager';
 import {EgEvent, EventService} from '@eg/core/event.service';
 import {IdlObject} from '@eg/core/idl.service';
@@ -13,6 +13,10 @@ import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
 import {CancelDialogComponent} from './cancel-dialog.component';
 
+const DELETABLE_STATES = [
+    'new', 'selector-ready', 'order-ready', 'approved', 'pending-order'
+]
+
 @Component({
   templateUrl: 'lineitem-list.component.html',
   selector: 'eg-lineitem-list',
@@ -422,18 +426,12 @@ export class LineitemListComponent implements OnInit {
             'open-ils.acq.purchase_order.lineitem.delete' :
             'open-ils.acq.picklist.lineitem.delete';
 
-        let promise = Promise.resolve();
-
-        this.loading = true;
-
-        ids.forEach(id => {
-            promise = promise
-            .then(_ => this.net.request(
-                'open-ils.acq', method, this.auth.token(), id).toPromise()
-            );
-        });
-
-        promise.then(_ => this.load());
+        from(ids)
+        .pipe(concatMap(id =>
+            this.net.request('open-ils.acq', method, this.auth.token(), id)
+        ))
+        .pipe(concatMap(_ => from(this.load())))
+        .subscribe();
     }
 
     liHasRealCopies(li: IdlObject): boolean {
@@ -525,5 +523,15 @@ export class LineitemListComponent implements OnInit {
             queryParams: {li: fromAll ? this.lineitemIds : this.selectedIds()}
         });
     }
+
+    // For PO's, lineitems can only be deleted if they are pending order.
+    canDeleteLis(): boolean {
+        const li = this.pageOfLineitems[0];
+        return Boolean(this.picklistId) || (
+            Boolean(li) &&
+            DELETABLE_STATES.includes(li.state()) &&
+            Boolean(this.poId)
+        );
+    }
 }