Revert "refactor: quality inspection item query (backport #54511)" (#54557)

Revert "refactor: quality inspection item query (backport #54511) (#54539)"

This reverts commit b01049814a.
This commit is contained in:
Mihir Kandoi
2026-04-27 15:45:45 +05:30
committed by GitHub
parent 8569ff67ff
commit f869e86c9c
2 changed files with 65 additions and 58 deletions

View File

@@ -48,14 +48,26 @@ frappe.ui.form.on("Quality Inspection", {
// item code based on GRN/DN // item code based on GRN/DN
frm.set_query("item_code", function (doc) { frm.set_query("item_code", function (doc) {
let doctype = doc.reference_type;
if (doc.reference_type !== "Job Card") {
doctype =
doc.reference_type == "Stock Entry" ? "Stock Entry Detail" : doc.reference_type + " Item";
}
if (doc.reference_type && doc.reference_name) { if (doc.reference_type && doc.reference_name) {
let filters = {
from: doctype,
parent_doctype: doc.reference_type,
inspection_type: doc.inspection_type,
};
if (doc.reference_type == doctype) filters["reference_name"] = doc.reference_name;
else filters["parent"] = doc.reference_name;
return { return {
query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query", query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query",
filters: { filters: filters,
reference_doctype: doc.reference_type,
reference_name: doc.reference_name,
inspection_type: doc.inspection_type,
},
}; };
} }
}); });

View File

@@ -361,63 +361,58 @@ class QualityInspection(Document):
@frappe.whitelist() @frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs @frappe.validate_and_sanitize_search_inputs
def item_query(doctype, txt, searchfield, start, page_len, filters): def item_query(doctype, txt, searchfield, start, page_len, filters):
reference_doctype = filters.get("reference_doctype") from frappe.desk.reportview import get_match_cond
if not reference_doctype: from_doctype = cstr(filters.get("from"))
parent_doctype = cstr(filters.get("parent_doctype"))
if not from_doctype or not frappe.db.exists("DocType", from_doctype):
return [] return []
elif reference_doctype == "Job Card":
production_item, item_name = frappe.get_value(
"Job Card", filters.get("reference_name"), ["production_item", "item_name"]
)
return ((production_item, item_name),)
else:
my_filters = [
["items.parent", "=", filters.get("reference_name")],
"and",
["items.item_code", "like", f"%{txt}%"],
"and",
["docstatus", "<", 2],
"and",
["items.quality_inspection", "is", "not set"],
]
if reference_doctype == "Stock Entry": mcond = get_match_cond(parent_doctype or from_doctype)
my_filters.extend( cond, qi_condition = "", "and (quality_inspection is null or quality_inspection = '')"
[
"and", if filters.get("parent"):
["items.t_warehouse", "is", "not set"], if (
] from_doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]
) and filters.get("inspection_type") != "In Process"
elif filters.get("inspection_type") != "In Process": ):
my_filters.extend( cond = """and item_code in (select name from `tabItem` where
[ inspection_required_before_purchase = 1)"""
"and", elif (
[ from_doctype in ["Sales Invoice Item", "Delivery Note Item"]
"items.item_code", and filters.get("inspection_type") != "In Process"
"in", ):
frappe.get_list( cond = """and item_code in (select name from `tabItem` where
"Item", inspection_required_before_delivery = 1)"""
filters={ elif from_doctype == "Stock Entry Detail":
"inspection_required_before_purchase" cond = """and s_warehouse is null"""
if filters.get("inspection_type") == "Incoming"
else "inspection_required_before_delivery": 1 if from_doctype in ["Supplier Quotation Item"]:
}, qi_condition = ""
pluck="name",
), return frappe.db.sql(
], f"""
] SELECT distinct item_code, item_name
FROM `tab{from_doctype}`
WHERE parent=%(parent)s and docstatus < 2 and item_code like %(txt)s
{qi_condition} {cond} {mcond}
ORDER BY item_code limit {cint(page_len)} offset {cint(start)}
""",
{"parent": filters.get("parent"), "txt": "%%%s%%" % txt},
) )
return frappe.get_query( elif filters.get("reference_name"):
reference_doctype, return frappe.db.sql(
fields=["items.item_code, items.item_name"], f"""
filters=my_filters, SELECT production_item
offset=start, FROM `tab{from_doctype}`
limit=page_len, WHERE name = %(reference_name)s and docstatus < 2 and production_item like %(txt)s
order_by="items.item_code", {qi_condition} {cond} {mcond}
ignore_permissions=False, ORDER BY production_item
distinct=True, limit {cint(page_len)} offset {cint(start)}
).run() """,
{"reference_name": filters.get("reference_name"), "txt": "%%%s%%" % txt},
)
@frappe.whitelist() @frappe.whitelist()