diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index 7c6b892416bad55084fffff497c875ae68824933..bf1c918668f1b9f70a6c1af76e3bf97cad907e4e 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -197,8 +197,19 @@ class QualityInspection(Document): self.quality_inspection_template = template self.get_item_specification_details() + def on_update(self): + if ( + frappe.db.get_single_value("Stock Settings", "action_if_quality_inspection_is_not_submitted") + == "Warn" + ): + self.update_qc_reference() + def on_submit(self): - self.update_qc_reference() + if ( + frappe.db.get_single_value("Stock Settings", "action_if_quality_inspection_is_not_submitted") + == "Stop" + ): + self.update_qc_reference() def on_cancel(self): self.ignore_linked_doctypes = "Serial and Batch Bundle" @@ -206,15 +217,15 @@ class QualityInspection(Document): self.update_qc_reference() def on_trash(self): - self.update_qc_reference() + self.update_qc_reference(remove_reference=True) 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): - quality_inspection = self.name if self.docstatus == 1 else "" + def update_qc_reference(self, remove_reference=False): + quality_inspection = self.name if self.docstatus < 2 and not remove_reference else "" if self.reference_type == "Job Card": if self.reference_name: @@ -244,7 +255,7 @@ class QualityInspection(Document): ) ) - if self.batch_no and self.docstatus == 1: + if self.batch_no and self.docstatus < 2: query = query.where(child_doc.batch_no == self.batch_no) if self.docstatus == 2: # if cancel, then remove qi link wherever same name