fix: barcode field on line item not working (#40381)
diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js
index e9c409e..3181d76 100644
--- a/erpnext/public/js/controllers/stock_controller.js
+++ b/erpnext/public/js/controllers/stock_controller.js
@@ -11,6 +11,18 @@
}
}
+ barcode(doc, cdt, cdn) {
+ let row = locals[cdt][cdn];
+ if (row.barcode) {
+ erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
+ frappe.model.set_value(cdt, cdn, {
+ "item_code": r.message.item_code,
+ "qty": 1,
+ });
+ });
+ }
+ }
+
setup_warehouse_query() {
var me = this;
erpnext.queries.setup_queries(this.frm, "Warehouse", function() {
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index f43e3e7..3a4615d 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -411,6 +411,19 @@
barcode_scanner.process_scan();
}
+ barcode(doc, cdt, cdn) {
+ let row = locals[cdt][cdn];
+ if (row.barcode) {
+ erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
+ debugger
+ frappe.model.set_value(cdt, cdn, {
+ "item_code": r.message.item_code,
+ "qty": 1,
+ });
+ });
+ }
+ }
+
validate_has_items () {
let table = this.frm.doc.items;
this.frm.has_items = (table && table.length
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index f17f60a..7655ad9 100755
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -2,6 +2,7 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext");
frappe.provide("erpnext.utils");
+frappe.provide("erpnext.stock.utils");
$.extend(erpnext, {
get_currency: function (company) {
@@ -1201,3 +1202,10 @@
context.show_serial_batch_selector(grid_row.frm, grid_row.doc, "", "", true);
});
}
+
+$.extend(erpnext.stock.utils, {
+ set_item_details_using_barcode(frm, child_row, callback) {
+ const barcode_scanner = new erpnext.utils.BarcodeScanner({ frm: frm });
+ barcode_scanner.scan_api_call(child_row.barcode, callback);
+ },
+});