From 3d0f6494115331ed4052e025da74eb212ab3b84c Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 13 Jan 2026 12:28:56 +0530 Subject: [PATCH] feat: support for serial item --- erpnext/stock/doctype/stock_entry/stock_entry.py | 12 +++++++++++- erpnext/stock/serial_batch_bundle.py | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 7d5f756e49f..e92ab143588 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -3435,6 +3435,7 @@ def move_sample_to_retention_warehouse(company, items): ) sabb = cls_obj.duplicate_package() batches = get_batch_nos(item.get("serial_and_batch_bundle")) + sabe_list = [] for batch_no in batches.keys(): sample_quantity = validate_sample_quantity( item.get("item_code"), @@ -3446,11 +3447,20 @@ def move_sample_to_retention_warehouse(company, items): sabe = next(item for item in sabb.entries if item.batch_no == batch_no) if sample_quantity: total_qty += sample_quantity - sabe.qty = -1 * sample_quantity + if sabb.has_serial_no: + sabe_list.extend( + [entry for entry in sabb.entries if entry.batch_no == batch_no][ + : int(sample_quantity) + ] + ) + else: + sabe.qty = -1 * sample_quantity else: sabb.entries.remove(sabe) if total_qty: + if sabe_list: + sabb.entries = sabe_list sabb.save() stock_entry.append( "items", diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 9cb4c25d782..50603eb609d 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -989,9 +989,10 @@ def get_batch_nos(serial_and_batch_bundle): entries = frappe.get_all( "Serial and Batch Entry", - fields=["batch_no", "qty", "name"], + fields=["batch_no", {"SUM": "qty", "as": "qty"}], filters={"parent": serial_and_batch_bundle, "batch_no": ("is", "set")}, order_by="idx", + group_by="batch_no", ) if not entries: