mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-02 13:08:27 +00:00
Revert "refactor: quality inspection item query (backport #54511) (#54539)"
This reverts commit b01049814a.
This commit is contained in:
@@ -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,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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(
|
mcond = get_match_cond(parent_doctype or from_doctype)
|
||||||
"Job Card", filters.get("reference_name"), ["production_item", "item_name"]
|
cond, qi_condition = "", "and (quality_inspection is null or quality_inspection = '')"
|
||||||
|
|
||||||
|
if filters.get("parent"):
|
||||||
|
if (
|
||||||
|
from_doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]
|
||||||
|
and filters.get("inspection_type") != "In Process"
|
||||||
|
):
|
||||||
|
cond = """and item_code in (select name from `tabItem` where
|
||||||
|
inspection_required_before_purchase = 1)"""
|
||||||
|
elif (
|
||||||
|
from_doctype in ["Sales Invoice Item", "Delivery Note Item"]
|
||||||
|
and filters.get("inspection_type") != "In Process"
|
||||||
|
):
|
||||||
|
cond = """and item_code in (select name from `tabItem` where
|
||||||
|
inspection_required_before_delivery = 1)"""
|
||||||
|
elif from_doctype == "Stock Entry Detail":
|
||||||
|
cond = """and s_warehouse is null"""
|
||||||
|
|
||||||
|
if from_doctype in ["Supplier Quotation Item"]:
|
||||||
|
qi_condition = ""
|
||||||
|
|
||||||
|
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 ((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":
|
elif filters.get("reference_name"):
|
||||||
my_filters.extend(
|
return frappe.db.sql(
|
||||||
[
|
f"""
|
||||||
"and",
|
SELECT production_item
|
||||||
["items.t_warehouse", "is", "not set"],
|
FROM `tab{from_doctype}`
|
||||||
]
|
WHERE name = %(reference_name)s and docstatus < 2 and production_item like %(txt)s
|
||||||
)
|
{qi_condition} {cond} {mcond}
|
||||||
elif filters.get("inspection_type") != "In Process":
|
ORDER BY production_item
|
||||||
my_filters.extend(
|
limit {cint(page_len)} offset {cint(start)}
|
||||||
[
|
""",
|
||||||
"and",
|
{"reference_name": filters.get("reference_name"), "txt": "%%%s%%" % txt},
|
||||||
[
|
)
|
||||||
"items.item_code",
|
|
||||||
"in",
|
|
||||||
frappe.get_list(
|
|
||||||
"Item",
|
|
||||||
filters={
|
|
||||||
"inspection_required_before_purchase"
|
|
||||||
if filters.get("inspection_type") == "Incoming"
|
|
||||||
else "inspection_required_before_delivery": 1
|
|
||||||
},
|
|
||||||
pluck="name",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.get_query(
|
|
||||||
reference_doctype,
|
|
||||||
fields=["items.item_code, items.item_name"],
|
|
||||||
filters=my_filters,
|
|
||||||
offset=start,
|
|
||||||
limit=page_len,
|
|
||||||
order_by="items.item_code",
|
|
||||||
ignore_permissions=False,
|
|
||||||
distinct=True,
|
|
||||||
).run()
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Reference in New Issue
Block a user