From 613c8158a8d939065439ccfaf8e3ebfe13bb067b Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Fri, 16 Sep 2022 17:49:00 -0400 Subject: [PATCH 1/2] fix: actually reject process_scan when update_table fails. --- erpnext/public/js/utils/barcode_scanner.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index a6bff2c148..6a80f92bc1 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -59,14 +59,14 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } me.update_table(data).then(row => { - row ? resolve(row) : reject(); - }); + resolve(row); + }).catch(() => reject()); }); }); } update_table(data) { - return new Promise(resolve => { + return new Promise((resolve, reject) => { let cur_grid = this.frm.fields_dict[this.items_table_name].grid; const {item_code, barcode, batch_no, serial_no, uom} = data; @@ -77,6 +77,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { if (this.dont_allow_new_row) { this.show_alert(__("Maximum quantity scanned for item {0}.", [item_code]), "red"); this.clean_up(); + reject(); return; } @@ -88,6 +89,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { if (this.is_duplicate_serial_no(row, serial_no)) { this.clean_up(); + reject(); return; } From 32e75ff80809bb7f9317ef1bf8d94b9dbbe6286f Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Fri, 16 Sep 2022 17:58:01 -0400 Subject: [PATCH 2/2] feat: audible indication of scan status. --- erpnext/public/js/utils/barcode_scanner.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 6a80f92bc1..83b108b874 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -21,6 +21,11 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { this.items_table_name = opts.items_table_name || "items"; this.items_table = this.frm.doc[this.items_table_name]; + // optional sound name to play when scan either fails or passes. + // see https://frappeframework.com/docs/v14/user/en/python-api/hooks#sounds + this.success_sound = opts.play_success_sound; + this.fail_sound = opts.play_fail_sound; + // any API that takes `search_value` as input and returns dictionary as follows // { // item_code: "HORSESHOE", // present if any item was found @@ -54,13 +59,18 @@ 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(); + this.play_fail_sound(); reject(); return; } me.update_table(data).then(row => { + this.play_success_sound(); resolve(row); - }).catch(() => reject()); + }).catch(() => { + this.play_fail_sound(); + reject(); + }); }); }); } @@ -221,6 +231,14 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { return this.items_table.find((d) => !d.item_code); } + play_success_sound() { + this.success_sound && frappe.utils.play_sound(this.success_sound); + } + + play_fail_sound() { + this.fail_sound && frappe.utils.play_sound(this.fail_sound); + } + clean_up() { this.scan_barcode_field.set_value(""); refresh_field(this.items_table_name);