From e69536c00b7136e6e25dd432a992b120871c465d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 27 Jul 2022 22:25:18 +0000 Subject: [PATCH] LP#1942220: (follow-up) add Vandelay step during PO activation Signed-off-by: Galen Charlton --- .../acq/lineitem/create-assets.component.html | 3 +- .../staff/acq/lineitem/create-assets.component.ts | 15 ++++- .../src/eg2/src/app/staff/acq/po/po.service.ts | 15 +++++ .../src/app/staff/acq/po/summary.component.html | 4 +- .../eg2/src/app/staff/acq/po/summary.component.ts | 75 ++++++++++++++++------ 5 files changed, 88 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.html b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.html index ecb72382e8..7144bc266d 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.html @@ -1,5 +1,6 @@ -

Load Bibs and Items

+

Load Bibs and Items

+

Load Bibs and Items, then Activate Order

diff --git a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.ts index 27c001dea3..3152b0d584 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/lineitem/create-assets.component.ts @@ -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 } } + ); + } + } } ); } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/po.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/po/po.service.ts index 07e7c67748..2d39d23725 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/po.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/po.service.ts @@ -90,6 +90,21 @@ export class PoService { }); } + checkIfImportNeeded(): Promise { + 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', diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html b/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html index 4881848ec2..30bae1d15f 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.html @@ -220,11 +220,11 @@ | - + | - + | diff --git a/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts index 6090d4714f..51fd162091 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/po/summary.component.ts @@ -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 { + load(useCache: boolean = true): Promise { 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 => { -- 2.11.0