diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.js b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.js index b02ad71b16..d50bdba3c9 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.js +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.js @@ -127,6 +127,14 @@ frappe.ui.form.on('Serial and Batch Bundle', { }, toggle_fields(frm) { + if (frm.doc.has_serial_no) { + frm.doc.entries.forEach(row => { + if (Math.abs(row.qty) !== 1) { + frappe.model.set_value(row.doctype, row.name, "qty", 1); + } + }) + } + frm.fields_dict.entries.grid.update_docfield_property( 'serial_no', 'read_only', !frm.doc.has_serial_no ); @@ -134,6 +142,10 @@ frappe.ui.form.on('Serial and Batch Bundle', { frm.fields_dict.entries.grid.update_docfield_property( 'batch_no', 'read_only', !frm.doc.has_batch_no ); + + frm.fields_dict.entries.grid.update_docfield_property( + 'qty', 'read_only', frm.doc.has_serial_no + ); }, set_queries(frm) { @@ -198,9 +210,9 @@ frappe.ui.form.on('Serial and Batch Bundle', { frappe.ui.form.on("Serial and Batch Entry", { - ledgers_add(frm, cdt, cdn) { + entries_add(frm, cdt, cdn) { if (frm.doc.warehouse) { - locals[cdt][cdn].warehouse = frm.doc.warehouse; + frappe.model.set_value(cdt, cdn, 'warehouse', frm.doc.warehouse); } }, }) \ No newline at end of file diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 7e5cac986e..cc55bd6ea8 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -133,7 +133,7 @@ class SerialandBatchBundle(Document): def calculate_total_qty(self, save=True): self.total_qty = 0.0 for d in self.entries: - d.qty = abs(d.qty) if d.qty else 0 + d.qty = 1 if self.has_serial_no and abs(d.qty) > 1 else abs(d.qty) if d.qty else 0 d.stock_value_difference = abs(d.stock_value_difference) if d.stock_value_difference else 0 if self.type_of_transaction == "Outward": d.qty *= -1