refactor: dont hardcode "scan_barcode" field

This commit is contained in:
Ankush Menat 2022-03-27 19:27:07 +05:30 committed by Ankush Menat
parent bd06ffab00
commit 893139f963

View File

@ -1,17 +1,25 @@
erpnext.stock.BarcodeScanner = class BarcodeScanner { erpnext.stock.BarcodeScanner = class BarcodeScanner {
constructor(opts) { constructor(opts) {
$.extend(this, opts); $.extend(this, opts);
this.scan_barcode_field = this.frm.fields_dict["scan_barcode"];
// field from which to capture input of scanned data
this.scan_field_name = opts.scan_field_name || "scan_barcode";
this.scan_barcode_field = this.frm.fields_dict[this.scan_field_name];
this.scan_api = opts.scan_api || "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number";
} }
process_scan() { process_scan() {
let me = this; let me = this;
if(this.frm.doc.scan_barcode) { const input = this.scan_barcode_field.value;
if (!input) {
return;
}
frappe.call({ frappe.call({
method: "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number", method: this.scan_api,
args: { args: {
search_value: this.frm.doc.scan_barcode search_value: input,
} }
}).then(r => { }).then(r => {
const data = r && r.message; const data = r && r.message;
@ -25,7 +33,6 @@ erpnext.stock.BarcodeScanner = class BarcodeScanner {
me.modify_table_after_scan(data); me.modify_table_after_scan(data);
}); });
}
this.clean_up(); this.clean_up();
} }