From 5e9275f02b5d75cbdae8abbf9a00eaa2d5149352 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 14 May 2022 15:19:48 -0400 Subject: [PATCH 1/2] feat: barcode scanner promise to return scanned row. --- erpnext/public/js/utils/barcode_scanner.js | 53 +++++++++++++--------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 3ae1234767c2..9b20aee5b9af 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -31,30 +31,38 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } process_scan() { - let me = this; + return new Promise((resolve, reject) => { + let me = this; - const input = this.scan_barcode_field.value; - if (!input) { - return; - } + const input = this.scan_barcode_field.value; + if (!input) { + return; + } - frappe - .call({ - method: this.scan_api, - args: { - search_value: input, - }, - }) - .then((r) => { - const data = r && r.message; - if (!data || Object.keys(data).length === 0) { - this.show_alert(__("Cannot find Item with this Barcode"), "red"); - this.clean_up(); - return; - } - - me.update_table(data); - }); + frappe + .call({ + method: this.scan_api, + args: { + search_value: input, + }, + }) + .then((r) => { + const data = r && r.message; + if (!data || Object.keys(data).length === 0) { + this.show_alert(__("Cannot find Item with this Barcode"), "red"); + this.clean_up(); + return; + } + + const row = me.update_table(data); + if (row) { + resolve(row); + } + else { + reject(); + } + }); + }); } update_table(data) { @@ -90,6 +98,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { this.set_batch_no(row, batch_no); this.set_barcode(row, barcode); this.clean_up(); + return row; } // batch and serial selector is reduandant when all info can be added by scan From 6e6f276aa04dcc354faede2fce76dd2d9c6d1a0c Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 14 May 2022 15:34:57 -0400 Subject: [PATCH 2/2] fix: missing reject at alternate code path --- erpnext/public/js/utils/barcode_scanner.js | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 9b20aee5b9af..d37811856460 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -51,6 +51,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { if (!data || Object.keys(data).length === 0) { this.show_alert(__("Cannot find Item with this Barcode"), "red"); this.clean_up(); + reject(); return; }