From 18abb2874415c1cf635db8ab94f5b770d54ca148 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 27 Mar 2022 18:43:36 +0530 Subject: [PATCH] fix(barcode_scan): dont add duplicate serial nos --- erpnext/public/js/controllers/transaction.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index eca59472a0c..cf2f3f627e4 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -390,6 +390,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.frm.script_manager.trigger("items_add", row_to_modify.doctype, row_to_modify.name); } + if (this.is_duplicate_serial_no(row_to_modify, data.serial_no)) { + scan_barcode_field.set_value(""); + return; + }; + this.show_scan_message(row_to_modify.idx, row_to_modify.item_code); this.set_scanned_values(row_to_modify, data, scan_barcode_field); } @@ -439,6 +444,18 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe return existing_batch_row || null; } + is_duplicate_serial_no(row, serial_no) { + const is_duplicate = !!serial_no && !!row.serial_no && row.serial_no.includes(serial_no); + + if (is_duplicate) { + frappe.show_alert({ + message: __('Serial No {0} is already added', [serial_no]), + indicator: 'orange' + }, 5); + } + return is_duplicate; + } + show_scan_message (idx, exist = null) { // show new row or qty increase toast if (exist) {