Skip to content

Commit

Permalink
Continue with QI
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Jan 19, 2025
1 parent c7d9843 commit 85d45de
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 18 deletions.
6 changes: 5 additions & 1 deletion lpp_co/custom/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@


class PurchaseReceiptLPP(PurchaseReceipt):
pass

def validate_inspection(self):
# LLP no checking on Purchase Receipt
return

# def validate_qi_presence_after_submit(self, row):
# """Check if QI is present on row level. Warn on submit if missing."""
# if not row.quality_inspection:
Expand Down
78 changes: 63 additions & 15 deletions lpp_co/custom/quality_inspection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2024, Ecosoft and contributors
# For license information, please see license.txt
import json
import frappe
from frappe.utils import cint, cstr
from erpnext.stock.doctype.quality_inspection.quality_inspection import QualityInspection
from frappe import _
from frappe.utils import get_link_to_form
Expand Down Expand Up @@ -31,20 +31,7 @@ def get_formula_evaluation_data(self, reading):
return data

def validate_inspection_required(self):
# Still not sure if we need to check?
# ------------------------------------
# doc = frappe.get_doc(self.reference_type, self.reference_name)
# if self.reference_type == "Purchase Receipt" and doc.get("docstatus", 0) == 1:
# if not frappe.get_cached_value(
# "Item", self.item_code, "custom_inspection_required_after_purchase_receipt"
# ):
# frappe.throw(
# _(
# "'Inspection Required after Purchase Receipt' has disabled for the item {0}, no need to create the QI"
# ).format(get_link_to_form("Item", self.item_code))
# )
# else:
# super().validate_inspection_required()
# For LPP, there is no checking on QI
return

def on_update(self):
Expand Down Expand Up @@ -146,3 +133,64 @@ def get_functional_testing_html(self):
order_by="name"
)
return frappe.render_template("lpp_co/custom/inspection_result/functional_testing.html", {"data": data})


# Override function, to remove inspection requried condition.
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def item_query(doctype, txt, searchfield, start, page_len, filters):
from frappe.desk.reportview import get_match_cond

from_doctype = cstr(filters.get("from"))
if not from_doctype or not frappe.db.exists("DocType", from_doctype):
return []

mcond = get_match_cond(from_doctype)
cond, qi_condition = "", "and (quality_inspection is null or quality_inspection = '')"

if filters.get("parent"):
# In LPP we do not need to worry about inspection requirement.
# 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 == "Stock Entry Detail":
cond = """and s_warehouse is null"""
# --

if from_doctype in ["Supplier Quotation Item"]:
qi_condition = ""

return frappe.db.sql(
f"""
SELECT item_code
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},
)

elif filters.get("reference_name"):
return frappe.db.sql(
f"""
SELECT production_item
FROM `tab{from_doctype}`
WHERE name = %(reference_name)s and docstatus < 2 and production_item like %(txt)s
{qi_condition} {cond} {mcond}
ORDER BY production_item
limit {cint(page_len)} offset {cint(start)}
""",
{"reference_name": filters.get("reference_name"), "txt": "%%%s%%" % txt},
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
# Copyright (c) 2025, Ecosoft and contributors
# For license information, please see license.txt

# import frappe
import frappe
from frappe import _
from frappe.model.document import Document


class QualityInspectionResult(Document):
pass

def validate(self):
self.validate_updatable()
self.set_accepted_rejected()
self.set_sepcification()

def on_trash(self):
self.validate_updatable()

def validate_updatable(self):
qi = frappe.get_doc("Quality Inspection", self.quality_inspection)
if qi.docstatus != 0:
status = qi.docstatus == 1 and _("submitted") or _("cancelled")
frappe.throw(
_("Modificatin of this result is not allowed!"
"<br/>Quality Inspection {} is already {}.")
.format(self.quality_inspection, status)
)

def set_accepted_rejected(self):
self.qty_accepted = len(list(filter(lambda r: r.result == "Accepted", self.readings)))
self.qty_rejected = len(list(filter(lambda r: r.result == "Rejected", self.readings)))

def set_sepcification(self):
item = frappe.get_cached_doc("Item", self.item)
def get_item_specification():
for spec in item.custom_item_specification_line:
if spec.specification == self.parameter:
return spec
return None
spec = get_item_specification()
if spec:
self.nominal = spec.nominal
self.delta_plus = spec.delta_plus
self.delta_minus = spec.delta_minus
28 changes: 28 additions & 0 deletions lpp_co/public/js/quality_inspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ frappe.ui.form.on("Quality Inspection", {
// });
// },

setup: function (frm) {
// item code based on GRN/DN
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) {
let filters = {
from: doctype,
inspection_type: doc.inspection_type,
};

if (doc.reference_type == doctype) filters["reference_name"] = doc.reference_name;
else filters["parent"] = doc.reference_name;

return {
query: "lpp_co.custom.quality_inspection.item_query",
filters: filters,
};
}
});

},

refresh: function(frm) {
frm.set_query("custom_quality_inspection_type", function () {
return {
Expand Down

0 comments on commit 85d45de

Please sign in to comment.