From 0794e5310b107b6fc51bb9f044fc4f99ad3158a9 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Tue, 26 Aug 2025 00:06:14 +0530 Subject: [PATCH 1/2] fix: match warehouse only when `last_scanned_warehouse` field exists --- erpnext/public/js/utils/barcode_scanner.js | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 0719e5ed99f..2301726072a 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -113,12 +113,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { frappe.flags.trigger_from_barcode_scanner = true; const { item_code, barcode, batch_no, serial_no, uom, default_warehouse } = data; - - const warehouse = this.has_last_scanned_warehouse - ? this.frm.doc.last_scanned_warehouse || default_warehouse - : null; - - let row = this.get_row_to_modify_on_scan(item_code, batch_no, uom, barcode, warehouse); + let row = this.get_row_to_modify_on_scan(item_code, batch_no, uom, barcode, default_warehouse); const is_new_row = !row?.item_code; if (!row) { if (this.dont_allow_new_row) { @@ -151,7 +146,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { () => this.set_serial_no(row, serial_no), () => this.set_batch_no(row, batch_no), () => this.set_barcode(row, barcode), - () => this.set_warehouse(row, warehouse), + () => this.set_warehouse(row), () => this.clean_up(), () => this.revert_selector_flag(), () => resolve(row), @@ -412,12 +407,16 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } } - async set_warehouse(row, warehouse) { + async set_warehouse(row) { + if (!this.has_last_scanned_warehouse) return; + + const last_scanned_warehouse = this.frm.doc.last_scanned_warehouse; + if (!last_scanned_warehouse) return; + const warehouse_field = this.get_warehouse_field(); + if (!warehouse_field || !frappe.meta.has_field(row.doctype, warehouse_field)) return; - if (warehouse && frappe.meta.has_field(row.doctype, warehouse_field)) { - await frappe.model.set_value(row.doctype, row.name, warehouse_field, warehouse); - } + await frappe.model.set_value(row.doctype, row.name, warehouse_field, last_scanned_warehouse); } show_scan_message(idx, is_existing_row = false, qty = 1) { @@ -438,15 +437,19 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { return is_duplicate; } - get_row_to_modify_on_scan(item_code, batch_no, uom, barcode, warehouse) { + get_row_to_modify_on_scan(item_code, batch_no, uom, barcode, default_warehouse) { let cur_grid = this.frm.fields_dict[this.items_table_name].grid; // Check if batch is scanned and table has batch no field let is_batch_no_scan = batch_no && frappe.meta.has_field(cur_grid.doctype, this.batch_no_field); let check_max_qty = this.max_qty_field && frappe.meta.has_field(cur_grid.doctype, this.max_qty_field); - const warehouse_field = this.get_warehouse_field(); - let has_warehouse_field = frappe.meta.has_field(cur_grid.doctype, warehouse_field); + const warehouse_field = this.has_last_scanned_warehouse && this.get_warehouse_field(); + const has_warehouse_field = + warehouse_field && frappe.meta.has_field(cur_grid.doctype, warehouse_field); + const warehouse = has_warehouse_field + ? this.frm.doc.last_scanned_warehouse || default_warehouse + : null; const matching_row = (row) => { const item_match = row.item_code == item_code; -- GitLab From 6f49f694d2d7ddcfe2c4a655d58a416e8fa349d7 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Tue, 26 Aug 2025 00:29:26 +0530 Subject: [PATCH 2/2] fix: correct logic for warehouse field label --- erpnext/public/js/utils/barcode_scanner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 2301726072a..b8d1b4afa2a 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -512,7 +512,8 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { handle_warehouse_scan(data) { const warehouse = data.warehouse; const warehouse_field = this.get_warehouse_field(); - const warehouse_field_label = frappe.meta.get_label(this.items_table_name, warehouse_field); + const cur_grid = this.frm.fields_dict[this.items_table_name].grid; + const warehouse_field_label = frappe.meta.get_label(cur_grid.doctype, warehouse_field); if (!this.last_scanned_warehouse_initialized) { this.setup_last_scanned_warehouse(); -- GitLab