Merge pull request #32102 from s-aga-r/fix/v14/stock-entry/send-to-subcontractor

fix: consider Stock Entry purpose while getting total supplied qty
This commit is contained in:
Sagar Sharma 2022-09-09 12:13:42 +05:30 committed by GitHub
commit 659d007bf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -875,25 +875,24 @@ class StockEntry(StockController):
) )
) )
parent = frappe.qb.DocType("Stock Entry") se = frappe.qb.DocType("Stock Entry")
child = frappe.qb.DocType("Stock Entry Detail") se_detail = frappe.qb.DocType("Stock Entry Detail")
conditions = (
(parent.docstatus == 1)
& (child.item_code == se_item.item_code)
& (
(parent.purchase_order == self.purchase_order)
if self.subcontract_data.order_doctype == "Purchase Order"
else (parent.subcontracting_order == self.subcontracting_order)
)
)
total_supplied = ( total_supplied = (
frappe.qb.from_(parent) frappe.qb.from_(se)
.inner_join(child) .inner_join(se_detail)
.on(parent.name == child.parent) .on(se.name == se_detail.parent)
.select(Sum(child.transfer_qty)) .select(Sum(se_detail.transfer_qty))
.where(conditions) .where(
(se.purpose == "Send to Subcontractor")
& (se.docstatus == 1)
& (se_detail.item_code == se_item.item_code)
& (
(se.purchase_order == self.purchase_order)
if self.subcontract_data.order_doctype == "Purchase Order"
else (se.subcontracting_order == self.subcontracting_order)
)
)
).run()[0][0] ).run()[0][0]
if flt(total_supplied, precision) > flt(total_allowed, precision): if flt(total_supplied, precision) > flt(total_allowed, precision):