Is Batch management broken in V13? Cannot set Quantity!

I am trying to execute a complete production cycle using ERPNext 13.0.0-beta.7, but encountering many apparent defects.

Batch quantity is one such defect.

There does not appear to be any way to set batch quantity.

When I finish a Work Order and attempt to submit the resulting Stock Entry with a batch number specified I get the error message:

Row #1: The batch IB2021-0001 has only 0.0 qty. Please select another batch which has 5.0 qty available or split the row into multiple rows, to deliver/issue from multiple batches

If I try to create a new Batch there is no field for setting the quantity.

NewBatch

If I save the new Batch, a Quantity field shows, but it is read only.

FinishedBatch

How can I solve this?

There is the Batch DocType and the Stock Entry DocTypes. Try adding the Batch Number prior to making the work Order or Stock Entry Transaction. Then you can just pick the Batch Number and say the quantity produced. Ensure you are setting only the Target Warehouse for the Output Items that are in the workorder/Stock Entry.

Hope this helps.

Thanks

Jay

I opened the Batch DocType for customization and found that batch_qty is set to Read Only unconditionally.

Is that not a bug?

Hi Martin,

TLDR: The batch_qty field on Batch is an aggregate sum of that Batch’s quantity in all Warehouses.

By itself, it doesn’t make much sense for Batch to carry quantity. Assume you manual enter a quantity of “5” on a Batch. Okay, which Warehouse(s) is that 5 units distributed amongst? Impossible to say, right?

The field is Read Only, because it’s just an aggregate qty, representing all the Batch qty in the system.

Try this instead:

  1. Perform a Stock Entry, placing 2 units of Batch ABC into Warehouse 1.
  2. Perform another Stock Entry, placing 3 units of Batch ABC into Warehouse 2.
  3. Re-examine the batch_qty on the Batch record. It should say 5.

Adding this batch_qty field was someone(s) design decision. They probably had a requirement, where a Report/Form needed to be sorted and filtered, based on the Total Batch Quantity. There were a few ways of handling this. The 2 most obvious choices:

  1. Handle this using Functions. The functions calculate total batch quantity in stock. The function result is used to modify the report data, sort, and filter.

  2. Create a new batch_qty SQL column on Batch. Update it whenever stock levels change. Now you can easily sort by a SQL column.

Option #2 was the easier choice, and has better performance.

Yet I strongly disagree with these types of aggregate fields. They violate the idea of SQL database normal form, and best practices for OLTP design. ERPNext must now store Batch Qty twice, in 2 different tables (inventory stock level, batch table). Code must ensure consistency between results. Yet it’s entirely possible for the 2 tables to get out-of-sync. When that happens, you’d see incorrect and inconsistent results on your screens and reports.

Thanks to open-source however, we always have the option to do Customization and private forks. I sometimes solve these problems in my local instances.

1 Like

No it is not. You make transactions using, not the Batch DocType but the appropriate stock transactions. The Batch Quantity is something that the code uses in the background.

Hope this helps.

Thanks

Jay

I greatly appreciate this analysis Brian. Thank you.

This is one part of my attempts to understand how to document/control Manufacture of anything using ERPNext, but in particular a dead trivial example for demonstration purposes described here if you haven’t seen it:

Hopefully with yours, @JayRam 's and other’s help I can document my experience to help others in the future.

I need to check out the solutions @JayRam suggests before I dig in deeper as you suggest. Give me a few days, ok?

Waiting for your good news, if in anyway, you need further help, please kindly let me know.