From 35478bbf913de49374ab043bc6515675df805e8e Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 19 Dec 2025 12:11:04 +0530 Subject: [PATCH 1/3] fix(stock): ignore reserved stock while calculating batch qty (cherry picked from commit b23c6e2687af087702409d3cd669519da0565044) # Conflicts: # erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py (cherry picked from commit ac2402dd2a6ce89a54e73070c1959eaad464e510) --- erpnext/stock/doctype/batch/batch.py | 9 ++++++++- .../serial_and_batch_bundle/serial_and_batch_bundle.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 20dd94da906..ba9aaa6c48a 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -159,8 +159,13 @@ class Batch(Document): @frappe.whitelist() def recalculate_batch_qty(self): batches = get_batch_qty( - batch_no=self.name, item_code=self.item, for_stock_levels=True, consider_negative_batches=True + batch_no=self.name, + item_code=self.item, + for_stock_levels=True, + consider_negative_batches=True, + ignore_reserved_stock=True, ) + batch_qty = 0.0 if batches: for row in batches: @@ -240,6 +245,7 @@ def get_batch_qty( for_stock_levels=False, consider_negative_batches=False, do_not_check_future_batches=False, + ignore_reserved_stock=False, ): """Returns batch actual qty if warehouse is passed, or returns dict of qty by warehouse if warehouse is None @@ -269,6 +275,7 @@ def get_batch_qty( "for_stock_levels": for_stock_levels, "consider_negative_batches": consider_negative_batches, "do_not_check_future_batches": do_not_check_future_batches, + "ignore_reserved_stock": ignore_reserved_stock, } ) diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index e20363cec3a..238d6600830 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -2332,6 +2332,12 @@ def get_auto_batch_nos(kwargs): sre_reserved_batches = frappe._dict() if not kwargs.ignore_reserved_stock: sre_reserved_batches = get_reserved_batches_for_sre(kwargs) +<<<<<<< HEAD +======= + + if kwargs.against_sales_order and only_consider_batches: + kwargs.batch_no = kwargs.warehouse = None +>>>>>>> b23c6e2687 (fix(stock): ignore reserved stock while calculating batch qty) picked_batches = frappe._dict() if kwargs.get("is_pick_list"): From 08cd08adcd5f50ba2b56b1cee2097b8e7da2d844 Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 19 Dec 2025 17:25:20 +0530 Subject: [PATCH 2/3] test(stock): add test for ignore reserve stock (cherry picked from commit 4d8ec5f54c0c063cc33990490947dd76fe029f94) (cherry picked from commit b20405dbf23cc52765bcd2c5229142838b85dfb9) --- erpnext/stock/doctype/batch/test_batch.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 1d44d19ac81..83efc12a7d8 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -324,6 +324,38 @@ class TestBatch(FrappeTestCase): self.assertEqual(get_batch_qty("batch a", "_Test Warehouse - _TC"), 90) + def test_ignore_reserved_qty(self): + from erpnext.selling.doctype.sales_order.sales_order import create_pick_list + from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order + + batch_item_name = "Reserve Batch Item" + batch_id = "Reserve Batch 1" + # Create Batch Item + self.make_batch_item(batch_item_name) + # Create Batch and Material Receipt Entry with qty 90 + self.make_new_batch_and_entry(batch_item_name, batch_id, "_Test Warehouse - _TC") + + # Enable Stock Reservation + frappe.db.set_single_value("Stock Settings", "enable_stock_reservation", 1) + + # Create Sales Order with qty 50 + sales_order = make_sales_order( + item_code=batch_item_name, warehouse="_Test Warehouse - _TC", qty=50, rate=20 + ) + + # Create Pick List for the Sales Order + pl = create_pick_list(sales_order.name) + pl.submit() + # Create Stock Reservation Entries + pl.create_stock_reservation_entries(notify=False) + + batch = frappe.get_doc("Batch", batch_id) + # Recalculate Batch Qty + batch.recalculate_batch_qty() + batch.reload() + # Case: Ignore Reserved Qty + self.assertEqual(batch.batch_qty, 90) + def test_total_batch_qty(self): self.make_batch_item("ITEM-BATCH-3") existing_batch_qty = flt(frappe.db.get_value("Batch", "B100", "batch_qty")) From 58c793f14ed7848433ccdfabca9792280f358eea Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 19 Dec 2025 18:07:42 +0530 Subject: [PATCH 3/3] chore: fix conflicts Removed logic for handling reserved stock when calculating batch quantity. (cherry picked from commit 9ade0725e8eb5f3ecdbc9cc7d6f5f6af6fd1748c) --- .../serial_and_batch_bundle/serial_and_batch_bundle.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 238d6600830..e20363cec3a 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -2332,12 +2332,6 @@ def get_auto_batch_nos(kwargs): sre_reserved_batches = frappe._dict() if not kwargs.ignore_reserved_stock: sre_reserved_batches = get_reserved_batches_for_sre(kwargs) -<<<<<<< HEAD -======= - - if kwargs.against_sales_order and only_consider_batches: - kwargs.batch_no = kwargs.warehouse = None ->>>>>>> b23c6e2687 (fix(stock): ignore reserved stock while calculating batch qty) picked_batches = frappe._dict() if kwargs.get("is_pick_list"):