perf: batch status check for on-hold/closed documents, remove N+1 queries (backport #54798) (#55573)

* perf: batch status check for on-hold/closed documents, remove N+1 queries (#54798)

(cherry picked from commit 5074597d00)

# Conflicts:
#	erpnext/buying/doctype/purchase_order/purchase_order.py

* chore: resolve conflicts

---------

Co-authored-by: Shubh Doshi <124681920+shubhdoshi21@users.noreply.github.com>
Co-authored-by: Mihir Kandoi <kandoimihir@gmail.com>
This commit is contained in:
mergify[bot]
2026-06-03 16:00:54 +00:00
committed by GitHub
parent 6a503f834c
commit 0274afe560
9 changed files with 62 additions and 66 deletions

View File

@@ -727,19 +727,6 @@ class BuyingController(SubcontractingController):
)
)
def check_for_on_hold_or_closed_status(self, ref_doctype, ref_fieldname):
for d in self.get("items"):
if d.get(ref_fieldname):
status = frappe.db.get_value(ref_doctype, d.get(ref_fieldname), "status")
if status in ("Closed", "On Hold"):
frappe.throw(
_("{ref_doctype} {ref_name} is {status}.").format(
ref_doctype=frappe.bold(_(ref_doctype)),
ref_name=frappe.bold(d.get(ref_fieldname)),
status=frappe.bold(_(status)),
)
)
def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_voucher=False):
self.update_ordered_and_reserved_qty()