LP#1942220: fixes to PO item deletion
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 02:15:51 +0000 (21:15 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 02:15:51 +0000 (21:15 -0500)
- use an open-ils.acq method rather than PCRUD
- display the delete button under more circumstances

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

index 6e4d850..27bf722 100644 (file)
@@ -82,7 +82,7 @@
       <button class="btn btn-warning btn-sm ml-1" 
         (click)="disencumberCharge(charge)" *ngIf="canDisencumber(charge)" i18n>Disencumber</button>
       <button class="btn btn-danger btn-sm ml-1" 
-        (click)="removeCharge(charge)" *ngIf="canModify" i18n>Remove</button>
+        (click)="removeCharge(charge)" *ngIf="canDelete(charge)" i18n>Remove</button>
     </div>
   </div>
 </ng-container>
index 705be70..21464f9 100644 (file)
@@ -113,6 +113,27 @@ export class PoChargesComponent implements OnInit, OnDestroy {
         return true; // we're likely OK to disencumber
     }
 
+    canDelete(charge: IdlObject): boolean {
+        if (!this.po()) {
+            return false;
+        }
+
+        const debit = charge.fund_debit();
+        if (debit && debit.encumbrance() === 'f') {
+            return false; // if it's expended, we can't just delete it
+        }
+        if (debit.invoice_entry()) {
+            return false; // we shouldn't actually be a po_item that is
+                          // linked to an invoice_entry, but if we are,
+                          // do NOT touch
+        }
+        if (debit.invoice_items() && debit.invoice_items().length) {
+            return false; // we're linked to an invoice item, so the disposition of the
+                          // invoice entry should govern things
+        }
+        return true; // we're likely OK to delete
+    }
+
     disencumberCharge(charge: IdlObject) {
         this.disencumberChargeDialog.charge = charge;
         this.disencumberChargeDialog.open().subscribe(doIt => {
@@ -135,8 +156,14 @@ export class PoChargesComponent implements OnInit, OnDestroy {
         );
 
         if (!charge.isnew()) {
-            this.pcrud.remove(charge).toPromise()
-            .then(_ => this.poService.refreshOrderSummary());
+            return this.net.request(
+                'open-ils.acq',
+                'open-ils.acq.po_item.delete',
+                this.auth.token(), charge.id()
+            ).toPromise().then(res => {
+                const evt = this.evt.parse(res);
+                if (evt) { return Promise.reject(evt + ''); }
+            }).then(_ => this.poService.refreshOrderSummary(true));
         }
     }
 }