Automating Batch Scanning in ERPNext: Auto-Fill Entire Batch Quantity in Serial & Batch Bundle
Managing batches in ERPNext manufacturing or delivery workflows can become repetitive — especially when you deal with large batch-based inventory like paper rolls, fabrics, or disposable dish stock.
One of the small but time-consuming tasks users face is scanning a Batch Number and then manually entering its entire available quantity into the Serial and Batch Bundle table.
To simplify this, I’ve developed a custom solution that automatically fills the entire batch quantity in the Serial and Batch Bundle Doctype as soon as you scan the batch number. 💡
🧩 The Problem
In ERPNext, when users scan or enter a Batch Number inside a Serial and Batch Bundle document, ERPNext identifies the batch — but by default, it does not auto-fill the quantity.
That means users have to:
- Scan the batch number,
- Check available quantity in warehouse,
- Manually enter the quantity again.
For businesses handling hundreds of batches daily — such as paper dish manufacturers, textile units, or chemical distributors — this process adds unnecessary steps and potential errors.
⚙️ The Solution
I created a custom script for ERPNext’s Serial and Batch Bundle Doctype that:
- Detects a scanned Batch Number,
- Fetches the linked Item Code,
- Gets the available quantity of that batch from the selected warehouse,
- Automatically inserts a row in the child table with the full batch quantity.
Once you scan the batch, ERPNext instantly fills:
- Item Code
- Batch No
- Qty = total available quantity
- Warehouse
✅ No manual typing
✅ No risk of wrong quantities
✅ Fully compatible with Delivery Note, Work Order, or any custom manufacturing flow
🧵 Real-world Use Case
In my case, this customization was built for a paper dish manufacturing unit using ERPNext.
Each batch represents a roll of raw paper — scanning a batch should automatically pull the entire available quantity from stock.
Now, the operator simply scans the batch barcode and ERPNext takes care of the rest.
🔧 Benefits
- 💨 Faster Data Entry — scan and move on, no typing
- ✅ Error-Free Stock Management — always correct batch qty
- 📦 Consistent Production Data — perfect for automated process orders
- 🧾 Seamless Integration — works with Delivery Notes, Stock Entries, and Manufacturing Entries
If you’re running a batch-based manufacturing or trading business and want to simplify your ERPNext process — this small customization can save hours of repetitive work every day.
Client Script : For Doctype Serial and Batch Bundle
frappe.ui.form.on('Serial and Batch Bundle', {
custom_scan_barcode(frm) {
if(frm.doc.custom_scan_barcode){
frappe.call({
method: 'get_batch_details',
args: {
batch_no: frm.doc.custom_scan_barcode
},
callback: function(r) {
debugger;
if(r.item != frm.doc.item_code){
frappe.msgprint(__('Scanned Batch No does not belong to the selected Item'));
frm.set_value('scan_batch_no','');
return;
}
if (r.batch_qty > 0) {
let exists = false;
frm.doc.entries.forEach(batch => {
if(batch.batch_no == r.name){
exists = true;
}
});
if(exists){
frappe.msgprint(__('Batch already added'));
frm.set_value('custom_scan_barcode','');
return;
}
let row = frm.add_child('entries');
row.batch_no = r.name;
row.qty = r.batch_qty;
frm.refresh_field('entries');
frm.set_value('custom_scan_barcode','');
}else{
frappe.msgprint(__('Batch is not available in stock'));
}
}
});
}
}
})
Server Script for API Script Type: API, API Method: get_batch_details
batch = frappe.get_doc("Batch", frappe.form_dict.batch_no)
frappe.response["item"]= batch.item
frappe.response["batch_qty"]= batch.batch_qty
frappe.response["name"]= batch.name
Need to Create Custom Field in Batch and Bundle Doctype
Create one Custom Field scan_barcode field type Link , and options : Batch, field name must be custom_scan_barcode
Author: Jigar Tarpara
ERPNext Developer | Founder, Khatavahi BI Solutions LLP
💼 ERP Consulting | ⚙️ Custom App Development | 📊 Process Automation