From c726b3977387e767f0eb141e973f9d9ec4906c15 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 1 Apr 2025 13:26:28 +0530 Subject: [PATCH] fix: set draft QC in purchase document on creation of qc --- .../quality_inspection/quality_inspection.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index 7c6b892416b..bf1c918668f 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 -- GitLab