perf: don't query unless required (bp #26175)

re-order conditionals so queries are not evaluated unless required.
# Conflicts:
#	erpnext/stock/doctype/batch/batch.py
This commit is contained in:
Ankush
2021-06-24 20:58:07 +05:30
committed by GitHub
parent b4b76b75cd
commit 21e44b19f0
4 changed files with 10 additions and 11 deletions

View File

@@ -99,9 +99,10 @@ def validate_returned_items(doc):
frappe.throw(_("Row # {0}: Serial No {1} does not match with {2} {3}")
.format(d.idx, s, doc.doctype, doc.return_against))
if warehouse_mandatory and frappe.db.get_value("Item", d.item_code, "is_stock_item") \
and not d.get("warehouse"):
frappe.throw(_("Warehouse is mandatory"))
if (warehouse_mandatory and not d.get("warehouse") and
frappe.db.get_value("Item", d.item_code, "is_stock_item")
):
frappe.throw(_("Warehouse is mandatory"))
items_returned = True
@@ -462,4 +463,4 @@ def get_returned_serial_nos(child_doc, parent_doc):
for row in frappe.get_all(parent_doc.doctype, fields = fields, filters=filters):
serial_nos.extend(get_serial_nos(row.serial_no))
return serial_nos
return serial_nos