style: prettier js
This commit is contained in:
parent
9f0e7949aa
commit
17a2ceb5d1
@ -21,7 +21,9 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
// batch_no: "LOT12", // present if batch was scanned
|
// batch_no: "LOT12", // present if batch was scanned
|
||||||
// serial_no: "987XYZ", // present if serial no was scanned
|
// serial_no: "987XYZ", // present if serial no was scanned
|
||||||
// }
|
// }
|
||||||
this.scan_api = opts.scan_api || "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number";
|
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() {
|
||||||
@ -32,24 +34,26 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.call({
|
frappe
|
||||||
method: this.scan_api,
|
.call({
|
||||||
args: {
|
method: this.scan_api,
|
||||||
search_value: input,
|
args: {
|
||||||
}
|
search_value: input,
|
||||||
}).then(r => {
|
},
|
||||||
const data = r && r.message;
|
})
|
||||||
if (!data || Object.keys(data).length === 0) {
|
.then((r) => {
|
||||||
frappe.show_alert({
|
const data = r && r.message;
|
||||||
message: __('Cannot find Item with this Barcode'),
|
if (!data || Object.keys(data).length === 0) {
|
||||||
indicator: 'red'
|
frappe.show_alert({
|
||||||
});
|
message: __("Cannot find Item with this Barcode"),
|
||||||
this.clean_up();
|
indicator: "red",
|
||||||
return;
|
});
|
||||||
}
|
this.clean_up();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
me.update_table(data.item_code, data.barcode, data.batch_no, data.serial_no);
|
me.update_table(data.item_code, data.barcode, data.batch_no, data.serial_no);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
update_table(item_code, barcode, batch_no, serial_no) {
|
update_table(item_code, barcode, batch_no, serial_no) {
|
||||||
@ -57,7 +61,8 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
let row = null;
|
let row = null;
|
||||||
|
|
||||||
// Check if batch is scanned and table has batch no field
|
// Check if batch is scanned and table has batch no field
|
||||||
let batch_no_scan = Boolean(batch_no) && frappe.meta.has_field(cur_grid.doctype, this.batch_no_field);
|
let batch_no_scan =
|
||||||
|
Boolean(batch_no) && frappe.meta.has_field(cur_grid.doctype, this.batch_no_field);
|
||||||
|
|
||||||
if (batch_no_scan) {
|
if (batch_no_scan) {
|
||||||
row = this.get_batch_row_to_modify(batch_no);
|
row = this.get_batch_row_to_modify(batch_no);
|
||||||
@ -76,7 +81,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
if (this.is_duplicate_serial_no(row, serial_no)) {
|
if (this.is_duplicate_serial_no(row, serial_no)) {
|
||||||
this.clean_up();
|
this.clean_up();
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
this.show_scan_message(row.idx, row.item_code);
|
this.show_scan_message(row.idx, row.item_code);
|
||||||
this.set_item(row, item_code);
|
this.set_item(row, item_code);
|
||||||
@ -87,7 +92,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_item(row, item_code) {
|
set_item(row, item_code) {
|
||||||
const item_data = {item_code: item_code}
|
const item_data = { item_code: item_code };
|
||||||
item_data[this.qty_field] = (row[this.qty_field] || 0) + 1;
|
item_data[this.qty_field] = (row[this.qty_field] || 0) + 1;
|
||||||
frappe.model.set_value(row.doctype, row.name, item_data);
|
frappe.model.set_value(row.doctype, row.name, item_data);
|
||||||
}
|
}
|
||||||
@ -95,10 +100,10 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
set_serial_no(row, serial_no) {
|
set_serial_no(row, serial_no) {
|
||||||
if (serial_no && frappe.meta.has_field(row.doctype, this.serial_no_field)) {
|
if (serial_no && frappe.meta.has_field(row.doctype, this.serial_no_field)) {
|
||||||
const existing_serial_nos = row[this.serial_no_field];
|
const existing_serial_nos = row[this.serial_no_field];
|
||||||
let new_serial_nos = '';
|
let new_serial_nos = "";
|
||||||
|
|
||||||
if (!!existing_serial_nos) {
|
if (!!existing_serial_nos) {
|
||||||
new_serial_nos = existing_serial_nos + '\n' + serial_no;
|
new_serial_nos = existing_serial_nos + "\n" + serial_no;
|
||||||
} else {
|
} else {
|
||||||
new_serial_nos = serial_no;
|
new_serial_nos = serial_no;
|
||||||
}
|
}
|
||||||
@ -122,18 +127,24 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show_scan_message (idx, exist = null) {
|
show_scan_message(idx, exist = null) {
|
||||||
// show new row or qty increase toast
|
// show new row or qty increase toast
|
||||||
if (exist) {
|
if (exist) {
|
||||||
frappe.show_alert({
|
frappe.show_alert(
|
||||||
message: __('Row #{0}: Qty increased by 1', [idx]),
|
{
|
||||||
indicator: 'green'
|
message: __("Row #{0}: Qty increased by 1", [idx]),
|
||||||
}, 5);
|
indicator: "green",
|
||||||
|
},
|
||||||
|
5
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
frappe.show_alert({
|
frappe.show_alert(
|
||||||
message: __('Row #{0}: Item added', [idx]),
|
{
|
||||||
indicator: 'green'
|
message: __("Row #{0}: Item added", [idx]),
|
||||||
}, 5);
|
indicator: "green",
|
||||||
|
},
|
||||||
|
5
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,25 +152,27 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
|||||||
const is_duplicate = !!serial_no && !!row.serial_no && row.serial_no.includes(serial_no);
|
const is_duplicate = !!serial_no && !!row.serial_no && row.serial_no.includes(serial_no);
|
||||||
|
|
||||||
if (is_duplicate) {
|
if (is_duplicate) {
|
||||||
frappe.show_alert({
|
frappe.show_alert(
|
||||||
message: __('Serial No {0} is already added', [serial_no]),
|
{
|
||||||
indicator: 'orange'
|
message: __("Serial No {0} is already added", [serial_no]),
|
||||||
}, 5);
|
indicator: "orange",
|
||||||
|
},
|
||||||
|
5
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return is_duplicate;
|
return is_duplicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
get_batch_row_to_modify(batch_no) {
|
get_batch_row_to_modify(batch_no) {
|
||||||
// get row if batch already exists in table
|
// get row if batch already exists in table
|
||||||
const existing_batch_row = this.items_table.find(d => d.batch_no === batch_no);
|
const existing_batch_row = this.items_table.find((d) => d.batch_no === batch_no);
|
||||||
return existing_batch_row || null;
|
return existing_batch_row || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_row_to_modify_on_scan(row_to_modify, item_code) {
|
get_row_to_modify_on_scan(row_to_modify, item_code) {
|
||||||
// get an existing item row to increment or blank row to modify
|
// get an existing item row to increment or blank row to modify
|
||||||
const existing_item_row = this.items_table.find(d => d.item_code === item_code);
|
const existing_item_row = this.items_table.find((d) => d.item_code === item_code);
|
||||||
const blank_item_row = this.items_table.find(d => !d.item_code);
|
const blank_item_row = this.items_table.find((d) => !d.item_code);
|
||||||
|
|
||||||
if (existing_item_row) {
|
if (existing_item_row) {
|
||||||
row_to_modify = existing_item_row;
|
row_to_modify = existing_item_row;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user