fix: consider sle for negative stock validation

(cherry picked from commit 38f35acffe)
This commit is contained in:
Rohit Waghchaure
2026-02-16 23:02:15 +05:30
committed by Mergify
parent d2eabcbf74
commit ca8f324b51

View File

@@ -1545,10 +1545,13 @@ class SerialandBatchBundle(Document):
def get_available_qty_from_sabb(self): def get_available_qty_from_sabb(self):
batches = [d.batch_no for d in self.entries if d.batch_no] batches = [d.batch_no for d in self.entries if d.batch_no]
sle = frappe.qb.DocType("Stock Ledger Entry")
child = frappe.qb.DocType("Serial and Batch Entry") child = frappe.qb.DocType("Serial and Batch Entry")
query = ( query = (
frappe.qb.from_(child) frappe.qb.from_(child)
.inner_join(sle)
.on(child.parent == sle.serial_and_batch_bundle)
.select( .select(
child.batch_no, child.batch_no,
child.qty, child.qty,
@@ -1557,6 +1560,7 @@ class SerialandBatchBundle(Document):
) )
.where( .where(
(child.item_code == self.item_code) (child.item_code == self.item_code)
& (sle.is_cancelled == 0)
& (child.warehouse == self.warehouse) & (child.warehouse == self.warehouse)
& (child.is_cancelled == 0) & (child.is_cancelled == 0)
& (child.batch_no.isin(batches)) & (child.batch_no.isin(batches))