From 67eb0767170176b75f4fb304ece2ef8a5acbf5a8 Mon Sep 17 00:00:00 2001 From: Dan Briem Date: Sat, 10 Aug 2019 21:02:00 -0400 Subject: [PATCH] LP#1777698 Duplicate barcode alert appearing on new barcodes 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 --- Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js index 6813258c47..9b5b57e98d 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js @@ -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; } -- 2.11.0