lp1777675 Support Inventory Date Refactor user/khuckins/lp1777675-inventory-date-support
authorKyle Huckins <khuckins@catalyte.io>
Thu, 16 Aug 2018 21:07:19 +0000 (21:07 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Fri, 17 Aug 2018 20:13:59 +0000 (20:13 +0000)
- Properly utilize linked idl field for grid additions.
- Remove excessive fetching.
- Ensure checkin interface Inventory Date displays a static, non-updating timestamp.

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm
modified:   Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
modified:   Open-ILS/src/templates/staff/cat/bucket/copy/t_pending.tt2
modified:   Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2
modified:   Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
modified:   Open-ILS/src/templates/staff/cat/item/t_list.tt2
modified:   Open-ILS/src/templates/staff/cat/item/t_summary_pane.tt2
modified:   Open-ILS/src/templates/staff/circ/checkin/t_checkin_table.tt2
modified:   Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js
modified:   Open-ILS/web/js/ui/default/staff/cat/services/holdings.js
modified:   Open-ILS/web/js/ui/default/staff/circ/checkin/app.js
modified:   Open-ILS/web/js/ui/default/staff/circ/services/item.js

12 files changed:
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/templates/staff/cat/bucket/copy/t_pending.tt2
Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/src/templates/staff/cat/item/t_list.tt2
Open-ILS/src/templates/staff/cat/item/t_summary_pane.tt2
Open-ILS/src/templates/staff/circ/checkin/t_checkin_table.tt2
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js
Open-ILS/web/js/ui/default/staff/cat/services/holdings.js
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js
Open-ILS/web/js/ui/default/staff/circ/services/item.js

index 047feeb..ddddbc8 100644 (file)
@@ -380,20 +380,23 @@ sub update_last_copy_inventory {
     return $e->die_event unless $e->checkauth;
 
     my $copies = $$args{copy_list};
-    foreach my $copy (@$copies) {
-        my $existing_alci = $e->search_asset_last_copy_inventory({copy => $copy})->[0];
+    foreach my $copyid (@$copies) {
+        my $copy = $e->retrieve_asset_copy($copyid);
+        my $alci = $e->search_asset_last_copy_inventory({copy => $copyid})->[0];
 
-        if($existing_alci) {
-            $existing_alci->inventory_date('now');
-            $existing_alci->inventory_workstation($e->requestor->wsid);
-            $e->update_asset_last_copy_inventory($existing_alci) or return $e->die_event;
+        if($alci) {
+            $alci->inventory_date('now');
+            $alci->inventory_workstation($e->requestor->wsid);
+            $e->update_asset_last_copy_inventory($alci) or return $e->die_event;
         } else {
             my $alci = Fieldmapper::asset::last_copy_inventory->new;
             $alci->inventory_date('now');
             $alci->inventory_workstation($e->requestor->wsid);
-            $alci->copy($copy);
+            $alci->copy($copy->id);
             $e->create_asset_last_copy_inventory($alci) or return $e->die_event;
         }
+
+        $copy->last_copy_inventory($alci);
     }
     $e->commit;
     return 1;
index c3de5b7..e25c8c2 100644 (file)
@@ -3969,7 +3969,8 @@ sub checkin_flesh_events {
         if($alci->[0]) {
             $self->last_copy_inventory->id($alci->[0]->id);
         }
-     }
+    }
+    $self->copy->last_copy_inventory($self->last_copy_inventory);
 
     for my $evt (@{$self->events}) {
 
index 321139b..60c1146 100644 (file)
@@ -58,7 +58,7 @@
       {{item['call_number.record.simple_record.title']}}
     </a>
   </eg-grid-field>
-  <eg-grid-field path="_last_inventory_date" datatype="timestamp" label="[% l('Inventory Date') %]"></eg-grid-field>
-  <eg-grid-field path="_last_inventory_workstation" label="[% l('Inventory Workstation') %]"></eg-grid-field>
+  <eg-grid-field path="last_copy_inventory.inventory_date" datatype="timestamp" label="[% l('Inventory Date') %]"></eg-grid-field>
+  <eg-grid-field path="last_copy_inventory.inventory_workstation.name" label="[% l('Inventory Workstation') %]"></eg-grid-field>
 
 </eg-grid>
index b49bc22..43f3ee0 100644 (file)
@@ -43,7 +43,7 @@
       {{item['call_number.record.simple_record.title']}}
     </a>
   </eg-grid-field>
-  <eg-grid-field path="_last_inventory_date" datatype="timestamp" label="[% l('Inventory Date') %]"></eg-grid-field>
-  <eg-grid-field path="_last_inventory_workstation" label="[% l('Inventory Workstation') %]"></eg-grid-field>
+  <eg-grid-field path="last_copy_inventory.inventory_date" datatype="timestamp" label="[% l('Inventory Date') %]"></eg-grid-field>
+  <eg-grid-field path="last_copy_inventory.inventory_workstation.name" label="[% l('Inventory Workstation') %]"></eg-grid-field>
 
 </eg-grid>
index b1a5b74..4a1f92e 100644 (file)
       {{item['copy_alert_count']}}
       <button ng-disabled="item['copy_alert_count'] <= 0" class="btn btn-sm btn-default" ng-click="col.handlers.copyAlertsEdit(item['id'])">[% l('Manage') %]</button>
     </eg-grid-field>
-    <eg-grid-field label="[% l('Inventory Date') %]"          path="_last_inventory_date"></eg-grid-field>
-    <eg-grid-field label="[% l('Inventory Workstation') %]"   path="_last_inventory_workstation"></eg-grid-field>
+    <eg-grid-field label="[% l('Inventory Date') %]"          datatype="timestamp" path="last_copy_inventory.inventory_date"></eg-grid-field>
+    <eg-grid-field label="[% l('Inventory Workstation') %]"   path="last_copy_inventory.inventory_workstation.name"></eg-grid-field>
   
   </eg-grid>
 </div>
index ab3a4e1..7f54e9e 100644 (file)
     {{item['copy_alert_count']}}
     <button ng-disabled="item['copy_alert_count'] <= 0" class="btn btn-sm btn-default" ng-click="col.handlers.copyAlertsEdit(item['id'])">[% l('Manage') %]</button>
   </eg-grid-field>
-  <eg-grid-field label="[% l('Inventory Date') %]"        path="_last_copy_inventory.inventory_date" datatype="timestamp"></eg-grid-field>
-  <eg-grid-field label="[% l('Inventory Workstation') %]" path="_last_copy_inventory._inventory_workstation_name"></eg-grid-field>
+  <eg-grid-field label="[% l('Inventory Date') %]"        path="last_copy_inventory.inventory_date" datatype="timestamp"></eg-grid-field>
+  <eg-grid-field label="[% l('Inventory Workstation') %]" path="last_copy_inventory.inventory_workstation.name"></eg-grid-field>
   
 </eg-grid>
 
index a372711..e67ba11 100644 (file)
 
   <div class="flex-row">
     <div class="flex-cell">[% l('Inventory Date') %]</div>
-    <div class="flex-cell well">{{last_copy_inventory.inventory_date() | date:egDateAndTimeFormat}}</div>
+    <div class="flex-cell well">{{copy.last_copy_inventory().inventory_date() | date:egDateAndTimeFormat}}</div>
 
     <div class="flex-cell">[% l('Inventory Workstation') %]</div>
-    <div class="flex-cell well">{{last_copy_inventory.inventory_workstation().name()}}</div>
+    <div class="flex-cell well">{{copy.last_copy_inventory().inventory_workstation().name()}}</div>
 
     <div class="flex-cell"></div>
     <div class="flex-cell"></div>
index ff9b234..aef321d 100644 (file)
   <eg-grid-field path="au.*" parent-idl-class="au" hidden></eg-grid-field>
   <eg-grid-field path="transit.*" parent-idl-class="atc" hidden></eg-grid-field>
   <eg-grid-field path="hold.*" parent-idl-class="ahr" hidden></eg-grid-field>
-  <eg-grid-field path="alci.inventory_date" label="[% l('Inventory Date') %]" datatype="timestamp" parent-idl-class="alci" hidden></eg-grid-field>
-  <eg-grid-field path="alci.inventory_workstation" label="[% l('Inventory Workstation')%]" parent-idl-class="alci" hidden>{{item.alci["inventory_workstation.name"]}}</eg-grid-field>
+  <eg-grid-field path="acp.last_copy_inventory.inventory_date" label="[% l('Inventory Date') %]" datatype="timestamp" hidden></eg-grid-field>
+  <eg-grid-field path="acp.last_copy_inventory.inventory_workstation.name" label="[% l('Inventory Workstation')%]" hidden></eg-grid-field>
 </eg-grid>
 
index 2ebb0ee..2e78bac 100644 (file)
@@ -400,14 +400,6 @@ function($scope,  $routeParams,  bucketSvc , egGridDataProvider,   egCore) {
             return null;
         },
         allItemsRetrieved : function() {
-            angular.forEach($scope.gridControls.allItems(), function(copy) {
-                bucketSvc.fetchRecentInventoryData(copy).then(function(alci) {
-                    if (alci) {
-                        copy._last_inventory_date = alci.inventory_date();
-                        copy._last_inventory_workstation = alci.inventory_workstation().name();
-                    }
-                });
-            });
             $scope.context.selectPendingBC = true;
         }
     }
@@ -466,16 +458,6 @@ function($scope,  $q , $routeParams , $timeout , $window , $uibModal , bucketSvc
         setQuery : function(q) {
             if (q) query = q;
             return query;
-        },
-        allItemsRetrieved : function() {
-            angular.forEach($scope.gridControls.allItems(), function(copy) {
-                bucketSvc.fetchRecentInventoryData(copy).then(function(alci) {
-                    if (alci) {
-                        copy._last_inventory_date = alci.inventory_date();
-                        copy._last_inventory_workstation = alci.inventory_workstation().name();
-                    }
-                });
-            });
         }
     };
 
index 43b5a9f..90558ca 100644 (file)
@@ -13,10 +13,11 @@ function(egCore , $q) {
     };
 
     service.prototype.flesh = {   
-        flesh : 2, 
+        flesh : 3,
         flesh_fields : {
-            acp : ['status','location','circ_lib','parts','age_protect','copy_alerts'],
-            acn : ['prefix','suffix','copies']
+            acp : ['status','location','circ_lib','parts','age_protect','copy_alerts', 'last_copy_inventory'],
+            acn : ['prefix','suffix','copies'],
+            alci : ['inventory_workstation']
         }
     }
 
@@ -117,19 +118,6 @@ function(egCore , $q) {
                     }
                 });
 
-                //create a virtual field for displaying most recent inventory data
-                angular.forEach(svc.copies, function(cp) {
-                    egCore.pcrud.search('alci',
-                        {copy: cp.id},
-                        {flesh: 2, flesh_fields: {alci: ['inventory_workstation']}}
-                    ).then(function(alci) {
-                        if (alci) {
-                            cp._last_inventory_workstation = alci.inventory_workstation().name();
-                            cp._last_inventory_date = alci.inventory_date();
-                        }
-                    });
-                });
-
                 // create virtual field for copy alert count
                 angular.forEach(svc.copies, function (cp) {
                     if (cp.copy_alerts) cp.copy_alert_count = cp.copy_alerts.length;
index 2dfb5e7..d506341 100644 (file)
@@ -203,6 +203,9 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
             
             row_item['copy_barcode'] = row_item.acp.barcode();
 
+            if (row_item.acp.last_copy_inventory().inventory_date() == "now")
+                row_item.acp.last_copy_inventory().inventory_date(Date.now());
+
             if (row_item.mbts) {
                 var amt = Number(row_item.mbts.balance_owed());
                 if (amt != 0) {
index 4496741..a163694 100644 (file)
@@ -16,9 +16,10 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
         flesh : 4,
         flesh_fields : {
             acp : ['call_number','location','status','location','floating','circ_modifier',
-                'age_protect','circ_lib','copy_alerts'],
+                'age_protect','circ_lib','copy_alerts', 'last_copy_inventory'],
             acn : ['record','prefix','suffix','label_class'],
-            bre : ['simple_record','creator','editor']
+            bre : ['simple_record','creator','editor'],
+            alci : ['inventory_workstation']
         },
         select : { 
             // avoid fleshing MARC on the bre
@@ -45,13 +46,6 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
         limit :  1
     }
 
-    service.inventoryFlesh = {
-        flesh : 2,
-        flesh_fields : {
-            alci : ['inventory_workstation']
-        }
-    }
-
     //Retrieve separate copy, aacs, and accs information
     service.getCopy = function(barcode, id) {
         if (barcode) {
@@ -73,11 +67,6 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
             service.circFlesh).then(function(circ) {return circ});
     }
 
-    service.getInventory = function(id) {
-        return egCore.pcrud.search('alci', {copy : id },
-            service.inventoryFlesh).then(function(alci) {return alci});
-    }
-
     service.getSummary = function(id) {
         return circ_summary = egCore.net.request(
             'open-ils.circ',
@@ -112,29 +101,17 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
                 });
         }
 
-        var fetchInventory = function(copy) {
-            return service.getInventory(copy.id())
-                .then(function(alci) {
-                    if (alci) {
-                        copyData.last_copy_inventory = alci;
-                        return copyData;
-                    }
-                });
-        }
-
         return fetchCopy(barcode, id).then(function(res) {
 
             if(!res.copy) { return $q.when(); }
-            return fetchInventory(copyData.copy).then(function(invRes) {
-                return fetchCirc(copyData.copy).then(function(res) {
-                    if (copyData.circ) {
-                        return fetchSummary(copyData.circ).then(function() {
-                            return copyData;
-                        });
-                    } else {
+            return fetchCirc(copyData.copy).then(function(res) {
+                if (copyData.circ) {
+                    return fetchSummary(copyData.circ).then(function() {
                         return copyData;
-                    }
-                });
+                    });
+                } else {
+                    return copyData;
+                }
             });
         });
 
@@ -145,7 +122,6 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
         var copy;
         var circ;
         var circ_summary;
-        var last_copy_inventory;
         var lastRes = {};
 
         return service.retrieveCopyData(barcode, id)
@@ -182,10 +158,6 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
                                         flatCopy._circ_summary.checkout_workstation :
                                         '';
                 }
-                if (copyData.last_copy_inventory) {
-                    flatCopy._last_copy_inventory = egCore.idl.toHash(copyData.last_copy_inventory, true);
-                    flatCopy._last_copy_inventory._inventory_workstation_name = copyData.last_copy_inventory.inventory_workstation().name();
-                }
                 flatCopy.index = service.index++;
                 flatCopy.copy_alert_count = copyData.copy.copy_alerts().filter(function(aca) {
                     return !aca.ack_time();
@@ -216,7 +188,6 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
 
             return lastRes = {
                 copy : copyData.copy,
-                last_copy_inventory : copyData.last_copy_inventory,
                 index : flatCopy.index
             }
         });