LP1904036 Cancel transit improvements during checkin
authorBill Erickson <berickxx@gmail.com>
Thu, 29 Apr 2021 18:44:31 +0000 (14:44 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:33 +0000 (20:13 -0400)
In some cases, a checkin result may not have the transit for a copy that
was just put into transit.  When canceling transits, always fetch the
latest/open copy transit before attempting to cancel.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/src/eg2/src/app/staff/circ/checkin/checkin.component.ts

index 3b6d424..e2d8e66 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, ViewChild, OnInit, AfterViewInit, HostListener} from '@angular/core';
 import {Location} from '@angular/common';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
-import {from} from 'rxjs';
+import {empty, from} from 'rxjs';
 import {concatMap} from 'rxjs/operators';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
@@ -337,14 +337,30 @@ export class CheckinComponent implements OnInit, AfterViewInit {
 
 
     cancelTransits(rows: CheckinGridEntry[]) {
-        const ids = rows
-            .filter(row => Boolean(row.transit))
-            .map(row => row.transit.id());
 
-        if (ids.length > 0) {
-            this.cancelTransitDialog.transitIds = ids;
-            this.cancelTransitDialog.open().subscribe();
-        }
+        rows = rows.filter(row => row.copy && row.copy.status().id() === 6);
+
+        // Copies in transit are not always accompanied by their transit.
+        from(rows).pipe(concatMap(row => {
+            return from(
+                this.circ.findCopyTransit(row)
+                .then(transit => row.transit = transit)
+            );
+        }))
+        .pipe(concatMap(_ => {
+
+            const ids = rows
+                .filter(row => Boolean(row.transit))
+                .map(row => row.transit.id());
+
+            if (ids.length > 0) {
+                this.cancelTransitDialog.transitIds = ids;
+                return this.cancelTransitDialog.open();
+            } else {
+                return empty();
+            }
+
+        })).subscribe();
     }
 
     showRecordHolds(rows: CheckinGridEntry[]) {