LP#1777698 Duplicate barcode alert appearing on new barcodes user/dbriem/lp1777698_duplicate_warning_on_new_barcodes
authorDan Briem <dbriem@wlsmail.org>
Sun, 11 Aug 2019 01:02:00 +0000 (21:02 -0400)
committerDan Briem <dbriem@wlsmail.org>
Sun, 11 Aug 2019 01:02:00 +0000 (21:02 -0400)
When scanning new copy barcodes, ng-change quickly fires multiple times
and sends promises to check for duplicates. If 1234 exists and you scan
12345, if the 1234 promise resolves after 12345, it will indicate it's a
duplicate. This patch keeps a count of the promises sent and only the
latest promise will set the boolean to indicate if it's a duplicate.

Hard to test because the promises usually resolve in order:
1. Add a new holding with the first few characters of an unused barcode
2. Scan the new barcode multiple times until you see the dup error
3. Apply patch and scan the new barcode multiple times (no error)

Signed-off-by: Dan Briem <dbriem@wlsmail.org>
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 6813258..9b5b57e 100644 (file)
@@ -508,6 +508,7 @@ function(egCore , $q) {
                 $scope.empty_barcode = false;
                 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
                 $scope.empty_barcode_string = window.empty_barcode_string;
+                var duplicate_check_count = 0;
 
                 if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
 
@@ -524,8 +525,13 @@ function(egCore , $q) {
                     if ($scope.barcode != '') {
                         $scope.copy.empty_barcode = $scope.empty_barcode = false;
                         $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
+
+                        var duplicate_check_id = ++duplicate_check_count;
                         itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
-                            .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
+                            .then(function (state) {
+                                if (duplicate_check_id == duplicate_check_count)
+                                    $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state;
+                            });
                     } else {
                         $scope.copy.empty_barcode = $scope.empty_barcode = true;
                     }