From 4f363f5bf3da286999966f10d0cca22264f42199 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 20 Oct 2023 11:44:14 +0530 Subject: [PATCH] fix: partial reservation against SBB --- .../stock_reservation_entry.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py index e589628c62..c7a9e16d0e 100644 --- a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py +++ b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py @@ -935,20 +935,28 @@ def create_stock_reservation_entries_for_so_items( sre.from_voucher_no = item.from_voucher_no sre.from_voucher_detail_no = item.from_voucher_detail_no - if item.serial_and_batch_bundle: + if item.get("serial_and_batch_bundle"): sbb = frappe.get_doc("Serial and Batch Bundle", item.serial_and_batch_bundle) sre.reservation_based_on = "Serial and Batch" - for entry in sbb.entries: + + index, picked_qty = 0, 0 + while index < len(sbb.entries) and picked_qty < qty_to_be_reserved: + entry = sbb.entries[index] + qty = 1 if has_serial_no else min(abs(entry.qty), qty_to_be_reserved - picked_qty) + sre.append( "sb_entries", { "serial_no": entry.serial_no, "batch_no": entry.batch_no, - "qty": 1 if has_serial_no else abs(entry.qty), + "qty": qty, "warehouse": entry.warehouse, }, ) + index += 1 + picked_qty += qty + sre.save() sre.submit()