Can't Finsih Work Order, error related to Batch Bundle qty on submit of Stock Entry

I have a case when producing FG with batch. My setting is to create batch on confirm WO and use it when Finish.

In my case, plan to product 100, but end up finish only 80 because of losses during the process.

So at last step, when click Finish with 100, the Stock Entry will transfer only 80 (as expected).

But at the time click Finish 100, the Batch Bundle is created with 100 qty for my batch.

However, this contradict with the fact that only 80 will be produced and so it throw error on Stock Entry.

To get away with this error, I have to,

  1. Find the underlining Batch Bundle, and manually change the quantity from 100 to 80. Go back to Stock entry and submit.

or

  1. I made the extension app to correct the quantity,
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import SerialandBatchBundle


class SerialandBatchBundleLPP(SerialandBatchBundle):
    
	def set_serial_and_batch_values(self, parent, row, qty_field=None):
		# Auto adjust batch bundle qty to avoid warning, for a very specific case
		if (
      		parent.doctype == "Stock Entry"
        	and parent.stock_entry_type == "Manufacture"
         	and self.has_batch_no
			and self.type_of_transaction == "Inward"
		):
			# Case using batch (not serial), assume only 1 batch
			self.entries[0].qty = row.transfer_qty
			self.save()
		super().set_serial_and_batch_values(parent, row, qty_field=qty_field)

I am sure sure the above is consdered a Bug?

Ref: Can't Finsih Work Order, error stock entry with Batch Bundle. · Issue #45689 · frappe/erpnext · GitHub

Hi ,

If the loss is fixed then Try to add loss in BOM and try it again , system will allow to finish the work order with 100 qty and produced 80 qty with one batch no.

Thanks, unfortunately the loss is not fixed but was recorded as loss during job card.