Batch no issue when creating new row in child table

Hello, I use this code snippet to create a new row in Delivery Note Item grid. The issue is, ERPNext changes my batch number to something else.

rowItem = frappe.model.add_child(frm.doc, 'Delivery Note Item', 'items');

frappe.model.set_value(rowItem.doctype, rowItem.name, 'item_code', strItemCode);
frappe.model.set_value(rowItem.doctype, rowItem.name, 'uom', strItemUOM);
frappe.model.set_value(rowItem.doctype, rowItem.name, 'batch_no', strBatchName);
frappe.model.set_value(rowItem.doctype, rowItem.name, 'qty', flBatchQty);
frappe.model.set_value(rowItem.doctype, rowItem.name, 'against_sales_order', strSaleOrderName);
frappe.model.set_value(rowItem.doctype, rowItem.name, 'so_detail', strSaleOrderLineName);
frm.refresh_field("items");
  • We have disabled the “set_batch_number” in “sales_common.js” file but somehow ERPNext still changes it.
  • The rows which are created by “Get Items from Sales Order” doesn’t have this issue. I can set a batch number in these rows but when I creating new rows, my batch numbers changes.

What can we try to prevent changing batch numbers in the row?

Regards.

To prevent automatic calculations and so changing the batch info to completely else we use:

rowItem = frappe.model.add_child(frm.doc, 'Delivery Note Item', 'items');
rowItem.item_code=strItemCode;
rowItem.uom = strItemUOM;
rowItem.batch_no=strBatchName;
rowItem.qty=flBatchQty;
rowItem.against_sales_order=strSaleOrderName;
rowItem.so_detail=strSaleOrderLineName;

frm.refresh_field("items");

Thank you @youssef for the solution. :pray:

2 Likes