Merge pull request #39930 from rohitwaghchaure/fixed-use-serial-batch-fields-for-se
fix: use serial batch fields not enabled for new stock entry
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index ba53cf8..1975c34 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -234,7 +234,7 @@
}
set_fields_onload_for_line_item() {
- if (this.frm.is_new && this.frm.doc?.items) {
+ if (this.frm.is_new() && this.frm.doc?.items) {
this.frm.doc.items.forEach(item => {
if (item.docstatus === 0
&& frappe.meta.has_field(item.doctype, "use_serial_batch_fields")
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 8da3e8f..6753a3a 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -936,6 +936,7 @@
this.toggle_related_fields(this.frm.doc);
this.toggle_enable_bom();
this.show_stock_ledger();
+ this.set_fields_onload_for_line_item();
erpnext.utils.view_serial_batch_nos(this.frm);
if (this.frm.doc.docstatus===1 && erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
this.show_general_ledger();
@@ -944,6 +945,35 @@
erpnext.utils.add_item(this.frm);
}
+ serial_no(doc, cdt, cdn) {
+ var item = frappe.get_doc(cdt, cdn);
+
+ if (item?.serial_no) {
+ // Replace all occurences of comma with line feed
+ item.serial_no = item.serial_no.replace(/,/g, '\n');
+ item.conversion_factor = item.conversion_factor || 1;
+
+ let valid_serial_nos = [];
+ let serialnos = item.serial_no.split("\n");
+ for (var i = 0; i < serialnos.length; i++) {
+ if (serialnos[i] != "") {
+ valid_serial_nos.push(serialnos[i]);
+ }
+ }
+ frappe.model.set_value(item.doctype, item.name,
+ "qty", valid_serial_nos.length / item.conversion_factor);
+ }
+ }
+
+ set_fields_onload_for_line_item() {
+ if (this.frm.is_new() && this.frm.doc?.items
+ && cint(frappe.user_defaults?.use_serial_batch_fields) === 1) {
+ this.frm.doc.items.forEach(item => {
+ frappe.model.set_value(item.doctype, item.name, "use_serial_batch_fields", 1);
+ })
+ }
+ }
+
scan_barcode() {
frappe.flags.dialog_set = false;
const barcode_scanner = new erpnext.utils.BarcodeScanner({frm:this.frm});
@@ -1074,6 +1104,10 @@
if(!row.s_warehouse) row.s_warehouse = this.frm.doc.from_warehouse;
if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse;
+
+ if (cint(frappe.user_defaults?.use_serial_batch_fields)) {
+ frappe.model.set_value(row.doctype, row.name, "use_serial_batch_fields", 1);
+ }
}
from_warehouse(doc) {