LP#1942220: implement LI search action apply claim policy
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 22:56:53 +0000 (17:56 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 22:56:53 +0000 (17:56 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts

index 8d6af1b..d348ba3 100644 (file)
@@ -3,6 +3,10 @@
   defaultSearchSetting="eg.acq.search.default.lineitems"></eg-acq-search-form>
 
 <eg-acq-export-attributes-dialog #exportAttributesDialog></eg-acq-export-attributes-dialog>
+<eg-acq-claim-policy-dialog #claimPolicyDialog></eg-acq-claim-policy-dialog>
+
+<eg-string #claimPolicyAppliedString i18n-text text="Claim Policy Applied to Selected Line Item(s)"></eg-string>
+
 <eg-alert-dialog #noActionableLIs i18n-dialogBody
   dialogBody="None of the selected line items are suitable for the action.">
 </eg-alert-dialog>
index b0667f3..2cb7b67 100644 (file)
@@ -10,9 +10,12 @@ import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
 import {AcqSearchService, AcqSearchTerm, AcqSearch} from './acq-search.service';
 import {LineitemService} from '../lineitem/lineitem.service';
+import {ToastService} from '@eg/share/toast/toast.service';
 import {ExportAttributesDialogComponent} from '../lineitem/export-attributes-dialog.component';
 import {AcqSearchFormComponent} from './acq-search-form.component';
+import {StringComponent} from '@eg/share/string/string.component';
 import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
+import {ClaimPolicyDialogComponent} from '../lineitem/claim-policy-dialog.component';
 
 @Component({
   selector: 'eg-lineitem-results',
@@ -26,6 +29,8 @@ export class LineitemResultsComponent implements OnInit {
     @ViewChild('acqSearchForm', { static: true}) acqSearchForm: AcqSearchFormComponent;
     @ViewChild('acqSearchLineitemsGrid', { static: true }) lineitemResultsGrid: GridComponent;
     @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
+    @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
+    @ViewChild('claimPolicyAppliedString', { static: false }) claimPolicyAppliedString: StringComponent;
     @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
 
     noSelectedRows: (rows: IdlObject[]) => boolean;
@@ -37,6 +42,7 @@ export class LineitemResultsComponent implements OnInit {
         private route: ActivatedRoute,
         private net: NetService,
         private auth: AuthService,
+        private toast: ToastService,
         private liService: LineitemService,
         private acqSearch: AcqSearchService) {
     }
@@ -81,7 +87,45 @@ export class LineitemResultsComponent implements OnInit {
                     '/lineitem/' + row.id() + '/worksheet', '_blank');
     }
 
+    applyClaimPolicy(rows: IdlObject[]) {
+        // must be attached to a PO; while this is not
+        // strictly necessary, seems to make sense that
+        // a claim policy is relevant only once you know
+        // who the vendor is
+        const lis = rows.filter(l => l.purchase_order());
+        if (lis.length === 0) {
+            this.noActionableLIs.open();
+            return;
+        }
+        const ids = lis.map(x => Number(x.id()));
+
+        this.claimPolicyDialog.ids = ids;
+        this.claimPolicyDialog.open().subscribe(claimPolicy => {
+            if (!claimPolicy) { return; }
+
+            const lisToUpdate: IdlObject[] = [];
+            this.liService.getFleshedLineitems(ids, { fromCache: true }).subscribe(
+                liStruct => {
+                    liStruct.lineitem.claim_policy(claimPolicy);
+                    lisToUpdate.push(liStruct.lineitem);
+                },
+                err => { },
+                () => {
+                    this.net.request(
+                        'open-ils.acq',
+                        'open-ils.acq.lineitem.update',
+                        this.auth.token(), lisToUpdate
+                    ).toPromise().then(resp => {
+                        this.claimPolicyAppliedString.current()
+                        .then(str => this.toast.success(str));
+                    });
+                }
+            );
+        });
+    }
+
     createPurchaseOrder(rows: IdlObject[]) {
+        // must not be already attached to a PO
         const lis = rows.filter(l => !l.purchase_order());
         if (lis.length === 0) {
             this.noActionableLIs.open();