mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
Merge pull request #32497 from s-aga-r/fix/quality-inspection/status
chore: set `Quality Inspection` status based on readings status
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
"naming_series",
|
"naming_series",
|
||||||
"report_date",
|
"report_date",
|
||||||
"status",
|
"status",
|
||||||
|
"manual_inspection",
|
||||||
"column_break_4",
|
"column_break_4",
|
||||||
"inspection_type",
|
"inspection_type",
|
||||||
"reference_type",
|
"reference_type",
|
||||||
@@ -231,6 +232,12 @@
|
|||||||
"label": "Status",
|
"label": "Status",
|
||||||
"options": "\nAccepted\nRejected",
|
"options": "\nAccepted\nRejected",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "manual_inspection",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Manual Inspection"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-search",
|
"icon": "fa fa-search",
|
||||||
@@ -238,10 +245,11 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-12-18 19:59:55.710300",
|
"modified": "2022-10-04 22:00:13.995221",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Quality Inspection",
|
"name": "Quality Inspection",
|
||||||
|
"naming_rule": "By \"Naming Series\" field",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -262,5 +270,6 @@
|
|||||||
"search_fields": "item_code, report_date, reference_name",
|
"search_fields": "item_code, report_date, reference_name",
|
||||||
"show_name_in_global_search": 1,
|
"show_name_in_global_search": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "ASC"
|
"sort_order": "ASC",
|
||||||
|
"states": []
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,9 @@ class QualityInspection(Document):
|
|||||||
if self.readings:
|
if self.readings:
|
||||||
self.inspect_and_set_status()
|
self.inspect_and_set_status()
|
||||||
|
|
||||||
|
def before_submit(self):
|
||||||
|
self.validate_readings_status_mandatory()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_item_specification_details(self):
|
def get_item_specification_details(self):
|
||||||
if not self.quality_inspection_template:
|
if not self.quality_inspection_template:
|
||||||
@@ -65,6 +68,11 @@ class QualityInspection(Document):
|
|||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.update_qc_reference()
|
self.update_qc_reference()
|
||||||
|
|
||||||
|
def validate_readings_status_mandatory(self):
|
||||||
|
for reading in self.readings:
|
||||||
|
if not reading.status:
|
||||||
|
frappe.throw(_("Row #{0}: Status is mandatory").format(reading.idx))
|
||||||
|
|
||||||
def update_qc_reference(self):
|
def update_qc_reference(self):
|
||||||
quality_inspection = self.name if self.docstatus == 1 else ""
|
quality_inspection = self.name if self.docstatus == 1 else ""
|
||||||
|
|
||||||
@@ -124,6 +132,16 @@ class QualityInspection(Document):
|
|||||||
# if not formula based check acceptance values set
|
# if not formula based check acceptance values set
|
||||||
self.set_status_based_on_acceptance_values(reading)
|
self.set_status_based_on_acceptance_values(reading)
|
||||||
|
|
||||||
|
if not self.manual_inspection:
|
||||||
|
self.status = "Accepted"
|
||||||
|
for reading in self.readings:
|
||||||
|
if reading.status == "Rejected":
|
||||||
|
self.status = "Rejected"
|
||||||
|
frappe.msgprint(
|
||||||
|
_("Status set to rejected as there are one or more rejected readings."), alert=True
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
def set_status_based_on_acceptance_values(self, reading):
|
def set_status_based_on_acceptance_values(self, reading):
|
||||||
if not cint(reading.numeric):
|
if not cint(reading.numeric):
|
||||||
result = reading.get("reading_value") == reading.get("value")
|
result = reading.get("reading_value") == reading.get("value")
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ class TestQualityInspection(FrappeTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
readings = [
|
readings = [
|
||||||
{"specification": "Iron Content", "min_value": 0.1, "max_value": 0.9, "reading_1": "0.4"}
|
{"specification": "Iron Content", "min_value": 0.1, "max_value": 0.9, "reading_1": "1.0"}
|
||||||
]
|
]
|
||||||
|
|
||||||
qa = create_quality_inspection(
|
qa = create_quality_inspection(
|
||||||
@@ -184,6 +184,38 @@ class TestQualityInspection(FrappeTestCase):
|
|||||||
se.cancel()
|
se.cancel()
|
||||||
frappe.db.set_value("Stock Settings", None, "action_if_quality_inspection_is_rejected", "Stop")
|
frappe.db.set_value("Stock Settings", None, "action_if_quality_inspection_is_rejected", "Stop")
|
||||||
|
|
||||||
|
def test_qi_status(self):
|
||||||
|
make_stock_entry(
|
||||||
|
item_code="_Test Item with QA", target="_Test Warehouse - _TC", qty=1, basic_rate=100
|
||||||
|
)
|
||||||
|
dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True)
|
||||||
|
qa = create_quality_inspection(
|
||||||
|
reference_type="Delivery Note", reference_name=dn.name, status="Accepted", do_not_save=True
|
||||||
|
)
|
||||||
|
qa.readings[0].manual_inspection = 1
|
||||||
|
qa.save()
|
||||||
|
|
||||||
|
# Case - 1: When there are one or more readings with rejected status and parent manual inspection is unchecked, then parent status should be set to rejected.
|
||||||
|
qa.status = "Accepted"
|
||||||
|
qa.manual_inspection = 0
|
||||||
|
qa.readings[0].status = "Rejected"
|
||||||
|
qa.save()
|
||||||
|
self.assertEqual(qa.status, "Rejected")
|
||||||
|
|
||||||
|
# Case - 2: When all readings have accepted status and parent manual inspection is unchecked, then parent status should be set to accepted.
|
||||||
|
qa.status = "Rejected"
|
||||||
|
qa.manual_inspection = 0
|
||||||
|
qa.readings[0].status = "Accepted"
|
||||||
|
qa.save()
|
||||||
|
self.assertEqual(qa.status, "Accepted")
|
||||||
|
|
||||||
|
# Case - 3: When parent manual inspection is checked, then parent status should not be changed.
|
||||||
|
qa.status = "Accepted"
|
||||||
|
qa.manual_inspection = 1
|
||||||
|
qa.readings[0].status = "Rejected"
|
||||||
|
qa.save()
|
||||||
|
self.assertEqual(qa.status, "Accepted")
|
||||||
|
|
||||||
|
|
||||||
def create_quality_inspection(**args):
|
def create_quality_inspection(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user