Hi all,
I’m running into a issue trying to upgrade from ERPNext v14 to v15 related to how serial and batch data is handled.
In v14, we could reliably use sle.batch_no
in queries to get current stock per batch. However, in v15 this no longer works, because batch_no
is no longer stored in the Stock Ledger Entry. Instead, it’s now managed via the new “Serial and Batch Bundle” logic and recorded in the Serial and Batch Entry table.
What’s frustrating is that legacy entries in Stock Ledger Entry
still have batch_no
populated, while newer ones do not. This means any reporting or logic that relies on consistent batch tracking now has to handle both data models: either through sle.batch_no
or by joining with Serial and Batch Entry.
This kind of breaking change feels like it was introduced without enough consideration for those of us maintaining integrations or custom reporting. Backward compatibility and developer experience really took a hit here.
If anyone has already adapted a query like the one below to work in v15, I would really appreciate your help or pointers:
select
sle.item_code, item.item_group, sle.warehouse, sle.batch_no, item.stock_uom, item.purchase_uom, item.brand,
sum(sle.actual_qty) as qty,
sum(sle.stock_value_difference) AS total_value,
sum(sle.stock_value_difference) / sum(sle.actual_qty) as unit_value,
sle.company
from `tabBatch` batch
inner join `tabStock Ledger Entry` sle on sle.batch_no = batch.name and sle.item_code = batch.item
inner join `tabItem` item ON item.name = sle.item_code
inner join `tabWarehouse` whs ON whs.name = sle.warehouse
where batch.batch_qty > 0
and item.has_batch_no = 1
and sle.is_cancelled = 0
and sle.docstatus < 2
group by sle.warehouse, sle.batch_no, sle.item_code
having sum(sle.actual_qty) != 0;