feat: audible indication of scan status.
diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js
index 6a80f92..83b108b 100644
--- a/erpnext/public/js/utils/barcode_scanner.js
+++ b/erpnext/public/js/utils/barcode_scanner.js
@@ -21,6 +21,11 @@
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 @@
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 @@
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);