refactor: dont hardcode "scan_barcode" field
This commit is contained in:
parent
bd06ffab00
commit
893139f963
@ -1,31 +1,38 @@
|
|||||||
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;
|
||||||
frappe.call({
|
if (!input) {
|
||||||
method: "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number",
|
return;
|
||||||
args: {
|
|
||||||
search_value: this.frm.doc.scan_barcode
|
|
||||||
}
|
|
||||||
}).then(r => {
|
|
||||||
const data = r && r.message;
|
|
||||||
if (!data || Object.keys(data).length === 0) {
|
|
||||||
frappe.show_alert({
|
|
||||||
message: __('Cannot find Item with this Barcode'),
|
|
||||||
indicator: 'red'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
me.modify_table_after_scan(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) {
|
||||||
|
frappe.show_alert({
|
||||||
|
message: __('Cannot find Item with this Barcode'),
|
||||||
|
indicator: 'red'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
me.modify_table_after_scan(data);
|
||||||
|
});
|
||||||
this.clean_up();
|
this.clean_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user