fix: Increment batch qty if pre-existing batch is scanned

This commit is contained in:
marination 2021-09-30 14:03:40 +05:30
parent 596cf3951d
commit abf450dc70
2 changed files with 8 additions and 19 deletions

View File

@ -378,18 +378,14 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
let batch_no_scan = Boolean(data.batch_no) && frappe.meta.has_field(cur_grid.doctype, "batch_no"); let batch_no_scan = Boolean(data.batch_no) && frappe.meta.has_field(cur_grid.doctype, "batch_no");
if (batch_no_scan) { if (batch_no_scan) {
let duplicate = this.check_duplicate_batch_scan(data.batch_no); row_to_modify = this.get_batch_row_to_modify(data.batch_no);
if (duplicate) {
scan_barcode_field.set_value('');
return;
}
} else { } else {
// serial or barcode scan // serial or barcode scan
row_to_modify = this.get_row_to_modify_on_scan(row_to_modify, data); row_to_modify = this.get_row_to_modify_on_scan(row_to_modify, data);
} }
if (!row_to_modify || batch_no_scan) { if (!row_to_modify) {
// add new row if new item scanned or batch is scanned // add new row if new item/batch is scanned
row_to_modify = frappe.model.add_child(this.frm.doc, cur_grid.doctype, 'items'); row_to_modify = frappe.model.add_child(this.frm.doc, cur_grid.doctype, 'items');
} }
@ -408,8 +404,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
['serial_no', 'batch_no', 'barcode'].forEach(field => { ['serial_no', 'batch_no', 'barcode'].forEach(field => {
if (data[field] && frappe.meta.has_field(row_to_modify.doctype, field)) { if (data[field] && frappe.meta.has_field(row_to_modify.doctype, field)) {
let is_serial_no = row_to_modify[field] && field === "serial_no"; let is_serial_no = row_to_modify[field] && field === "serial_no";
let value = data[field]; let value = data[field];
if (is_serial_no) { if (is_serial_no) {
value = row_to_modify[field] + '\n' + data[field]; value = row_to_modify[field] + '\n' + data[field];
} }
@ -436,21 +432,14 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
return row_to_modify; return row_to_modify;
} }
check_duplicate_batch_scan(batch_no) { get_batch_row_to_modify(batch_no) {
// ignore scan if batch already exists in table // get row if batch already exists in table
const existing_batch_row = this.frm.doc.items.find(d => d.batch_no === batch_no); const existing_batch_row = this.frm.doc.items.find(d => d.batch_no === batch_no);
return existing_batch_row || null;
if (existing_batch_row) {
frappe.show_alert({
message: __('Batch {0} already added', [batch_no]),
indicator: 'orange'
});
return true;
}
return false;
} }
show_scan_message (idx, exist = null) { show_scan_message (idx, exist = null) {
// 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]), message: __('Row #{0}: Qty increased by 1', [idx]),

View File