LP#1942220: (follow-up) add Vandelay step during PO activation
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 27 Jul 2022 22:25:18 +0000 (22:25 +0000)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 27 Jul 2022 22:25:18 +0000 (22:25 +0000)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.html
Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.ts
Open-ILS/src/eg2/src/app/staff/acq/po/po.service.ts
Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html
Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts

index ecb7238..7144bc2 100644 (file)
@@ -1,5 +1,6 @@
 
-<h3 class="m-2" i18n>Load Bibs and Items</h3>
+<h3 *ngIf="!activatePo" class="m-2" i18n>Load Bibs and Items</h3>
+<h3 *ngIf="activatePo" class="m-2" i18n>Load Bibs and Items, then Activate Order</h3>
 
 <div class="w-100 m-2">
   <eg-acq-upload mode="getImportParams" [customAction]="createAssets"></eg-acq-upload>
index 27c001d..3152b0d 100644 (file)
@@ -1,5 +1,5 @@
 import {Component, OnInit, Input, Output} from '@angular/core';
-import {ActivatedRoute, Router, ParamMap} from '@angular/router';
+import {ActivatedRoute, Router, ParamMap, NavigationStart} from '@angular/router';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {EventService, EgEvent} from '@eg/core/event.service';
@@ -26,6 +26,7 @@ export class CreateAssetsComponent implements OnInit {
     targetPo: number;
     creationRequested = false;
     creatingAssets = false;
+    activatePo = false;
 
     creationStatus: AssetCreationResponse = {
         liProcessed: 0,
@@ -49,6 +50,7 @@ export class CreateAssetsComponent implements OnInit {
     ) { }
 
     ngOnInit() {
+        this.activatePo = history.state.activatePo ? true : false;
         this.route.parent.paramMap.subscribe((params: ParamMap) => {
             this.targetPo = +params.get('poId');
         });
@@ -60,6 +62,7 @@ export class CreateAssetsComponent implements OnInit {
     createAssets = (args: Object) => {
         this.creatingAssets = true;
         this.creationRequested = true;
+        this.creationErrors = [];
 
         const assetArgs = {
             vandelay: args['vandelay']
@@ -87,7 +90,15 @@ export class CreateAssetsComponent implements OnInit {
             },
             err => {},
             () => {
-                this.creatingAssets = false;
+                if (!this.creationErrors.length) {
+                    this.creatingAssets = false;
+                    if (this.activatePo) {
+                        this.router.navigate(
+                            ['/staff/acq/po/' + this.targetPo],
+                            { state: { finishPoActivation: true } }
+                        );
+                    }
+                }
             }
         );
     }
index 07e7c67..2d39d23 100644 (file)
@@ -90,6 +90,21 @@ export class PoService {
         });
     }
 
+    checkIfImportNeeded(): Promise<boolean> {
+        return new Promise((resolve, reject) => {
+            this.pcrud.search('jub',
+                { purchase_order: this.currentPo.id(), eg_bib_id: null },
+                { limit: 1 }, { idlist: true, atomic: true }
+            ).toPromise().then(ids => {
+                if (ids && ids.length) {
+                    resolve(true);
+                } else {
+                    resolve(false);
+                }
+            });
+        });
+    }
+
     checkDuplicatePoName(orderAgency: number, poName: string, results: PoDupeCheckResults) {
         if (Boolean(orderAgency) && Boolean(poName)) {
             this.pcrud.search('acqpo',
index 4881848..30bae1d 100644 (file)
       </ng-container>
       <ng-container *ngIf="canActivate === true">
         <span class="pl-2 pr-2" i18n> | </span>
-        <button class="btn btn-sm btn-primary" (click)="activatePo(true)" i18n>Activate Without Loading Items</button>
+        <button class="btn btn-sm btn-primary" (click)="activatePo(true)" [disabled]="doingActivation" i18n>Activate Without Loading Items</button>
       </ng-container>
       <ng-container *ngIf="canActivate === true">
         <span class="pl-2 pr-2" i18n> | </span>
-        <button class="btn btn-sm btn-success" (click)="activatePo()" i18n>Activate Order</button>
+        <button class="btn btn-sm btn-success" (click)="activatePo()" [disabled]="doingActivation" i18n>Activate Order</button>
       </ng-container>
       <ng-container *ngIf="canFinalize">
         <span class="pl-2 pr-2" i18n> | </span>
index 6090d47..51fd162 100644 (file)
@@ -49,6 +49,8 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     canActivate: boolean = null;
     canFinalize = false;
     showLegacyLinks = false;
+    doingActivation = false;
+    finishPoActivation = false;
 
     activationBlocks: EgEvent[] = [];
     activationWarnings: EgEvent[] = [];
@@ -95,13 +97,18 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
         return this.poService.currentPo;
     }
 
-    load(): Promise<any> {
+    load(useCache: boolean = true): Promise<any> {
         if (!this.poId) { return Promise.resolve(); }
 
         this.dupeResults.dupeFound = false;
         this.dupeResults.dupePoId = -1;
 
-        return this.poService.getFleshedPo(this.poId, {fromCache: true, toCache: true})
+        if (history.state.finishPoActivation) {
+            this.doingActivation = true;
+            useCache = false;
+        }
+
+        return this.poService.getFleshedPo(this.poId, {fromCache: useCache, toCache: true})
         .then(po => {
 
             // EDI message count
@@ -122,7 +129,8 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
         })
         .then(_ => this.setCanActivate())
         .then(_ => this.setCanFinalize())
-        .then(_ => this.loadUiPrefs());
+        .then(_ => this.loadUiPrefs())
+        .then(_ => this.activatePoIfRequested());
     }
 
     // Can run via Enter or blur.  If it just ran via Enter, avoid
@@ -228,7 +236,7 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
             zero_copy_activate: this.zeroCopyActivate
         };
 
-        this.net.request('open-ils.acq',
+        return this.net.request('open-ils.acq',
             'open-ils.acq.purchase_order.activate.dry_run',
             this.auth.token(), this.poId, null, options
 
@@ -255,9 +263,13 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     }
 
     activatePo(noAssets?: boolean) {
+        this.doingActivation = true;
         if (this.activationWarnings.length) {
             this.confirmActivate.open().subscribe(confirmed => {
-                if (!confirmed) { return; }
+                if (!confirmed) {
+                    this.doingActivation = true;
+                    return;
+                }
 
                 this._activatePo(noAssets);
             });
@@ -267,23 +279,40 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
     }
 
     _activatePo(noAssets?: boolean) {
+        if (noAssets) {
+            // Bypass any Vandelay choices and force-load all records.
+            const vandelay = {
+                import_no_match: true,
+                queue_name: `ACQ ${new Date().toISOString()}`
+            };
+
+            const options = {
+                zero_copy_activate: this.zeroCopyActivate,
+                no_assets: noAssets
+            };
+
+            this._doActualActivate(vandelay, options);
+        } else {
+            this.poService.checkIfImportNeeded().then(importNeeded => {
+                if (importNeeded) {
+                    this.router.navigate(
+                        ['/staff/acq/po/' + this.po().id() + '/create-assets'],
+                        { state: { activatePo: true } }
+                    );
+                } else {
+                    // LIs are linked to bibs, so charge forward and activate with no options set
+                    this._doActualActivate({}, {});
+                }
+            });
+        }
+   }
+
+    _doActualActivate(vandelay: any, options: any) {
         this.activationEvent = null;
         this.progressDialog.open();
         this.progressDialog.update({max: this.po().lineitem_count() * 3});
 
-         // Bypass any Vandelay choices and force-load all records.
-         // TODO: Add intermediate Vandelay options.
-        const vandelay = {
-            import_no_match: true,
-            queue_name: `ACQ ${new Date().toISOString()}`
-        };
-
-        const options = {
-            zero_copy_activate: this.zeroCopyActivate,
-            no_assets: noAssets
-        };
-
-        this.net.request(
+         this.net.request(
             'open-ils.acq',
             'open-ils.acq.purchase_order.activate',
             this.auth.token(), this.poId, vandelay, options
@@ -299,7 +328,9 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
             if (Number(resp) === 1) {
                 this.progressDialog.close();
                 // Refresh everything.
-                location.href = location.href;
+                this.initDone = false;
+                this.doingActivation = false;
+                this.load(false).then(_ => this.initDone = true);
 
             } else {
                 this.progressDialog.update(
@@ -335,6 +366,12 @@ export class PoSummaryComponent implements OnInit, OnDestroy {
         });
     }
 
+    activatePoIfRequested() {
+        if (this.canActivate && history.state.finishPoActivation) {
+            this.activatePo(false);
+        }
+    }
+
     finalizePo() {
 
         this.confirmFinalize.open().subscribe(confirmed => {