Skip to content

Commit

Permalink
fix: consider Stock Entry purpose while getting total supplied qty
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Sep 6, 2022
1 parent 514d280 commit 8964612
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,15 +856,22 @@ def validate_purchase_order(self):
se_item.item_code, self.purchase_order
)
)
total_supplied = frappe.db.sql(
"""select sum(transfer_qty)
from `tabStock Entry Detail`, `tabStock Entry`
where `tabStock Entry`.purchase_order = %s
and `tabStock Entry`.docstatus = 1
and `tabStock Entry Detail`.item_code = %s
and `tabStock Entry Detail`.parent = `tabStock Entry`.name""",
(self.purchase_order, se_item.item_code),
)[0][0]

se = frappe.qb.DocType("Stock Entry")
se_detail = frappe.qb.DocType("Stock Entry Detail")

total_supplied = (
frappe.qb.from_(se)
.inner_join(se_detail)
.on(se.name == se_detail.parent)
.select(Sum(se_detail.transfer_qty))
.where(
(se.purpose == "Send to Subcontractor")
& (se.purchase_order == self.purchase_order)
& (se_detail.item_code == se_item.item_code)
& (se.docstatus == 1)
)
).run()[0][0]

if flt(total_supplied, precision) > flt(total_allowed, precision):
frappe.throw(
Expand Down

0 comments on commit 8964612

Please sign in to comment.