fix: stock reservation validation

This commit is contained in:
Rohit Waghchaure
2025-11-25 12:01:51 +05:30
parent d3c33d16ad
commit ca47ae6fd8

View File

@@ -25,6 +25,7 @@ from erpnext.controllers.sales_and_purchase_return import (
from erpnext.setup.doctype.brand.brand import get_brand_defaults from erpnext.setup.doctype.brand.brand import get_brand_defaults
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
from erpnext.stock import get_warehouse_account_map from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.batch.batch import get_batch_qty
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import ( from erpnext.stock.doctype.inventory_dimension.inventory_dimension import (
get_evaluated_inventory_dimension, get_evaluated_inventory_dimension,
) )
@@ -1216,6 +1217,12 @@ class StockController(AccountsController):
], ],
}.get(self.doctype) }.get(self.doctype)
qty_field = {
"Sales Invoice": "qty",
"Delivery Note": "qty",
"Stock Entry": "fg_completed_qty",
}.get(self.doctype)
reserved_batches_data = self.get_reserved_batches(batches) reserved_batches_data = self.get_reserved_batches(batches)
items = self.items items = self.items
if self.doctype == "Stock Entry": if self.doctype == "Stock Entry":
@@ -1236,6 +1243,17 @@ class StockController(AccountsController):
if row.voucher_no == value: if row.voucher_no == value:
continue continue
batch_qty = get_batch_qty(
row.batch_no,
row.warehouse,
posting_date=self.posting_date,
posting_time=self.posting_time,
consider_negative_batches=True,
)
if item.get(qty_field) < batch_qty:
continue
frappe.throw( frappe.throw(
_( _(
"The batch {0} is already reserved in {1} {2}. So, cannot proceed with the {3} {4}, which is created against the {5} {6}." "The batch {0} is already reserved in {1} {2}. So, cannot proceed with the {3} {4}, which is created against the {5} {6}."
@@ -1264,6 +1282,7 @@ class StockController(AccountsController):
doctype.voucher_type, doctype.voucher_type,
doctype.voucher_no, doctype.voucher_no,
doctype.item_code, doctype.item_code,
doctype.warehouse,
) )
.where((doctype.docstatus == 1) & (child_doc.batch_no.isin(batches))) .where((doctype.docstatus == 1) & (child_doc.batch_no.isin(batches)))
).run(as_dict=True) ).run(as_dict=True)