From c0cf1fed0058f6ce90871275a99fc7cb83a0c627 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 16 Jan 2025 17:33:21 +0530 Subject: [PATCH] fix: company in quality inspection (cherry picked from commit 397cd79e1e8dbe34b7de316dac43754ab5de7c90) --- .../quality_inspection/quality_inspection.js | 22 +++++++++++++++---- .../quality_inspection.json | 13 ++++++++--- .../quality_inspection/quality_inspection.py | 8 +++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.js b/erpnext/stock/doctype/quality_inspection/quality_inspection.js index 99e25bf5eb6..d9216fbb9a1 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.js +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.js @@ -4,12 +4,26 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type; frappe.ui.form.on("Quality Inspection", { + onload(frm) { + frm.trigger("set_default_company"); + }, + + set_default_company(frm) { + if (!frm.doc.company) { + frm.set_value("company", frappe.defaults.get_default("company")); + } + }, + setup: function (frm) { - frm.set_query("reference_name", function () { + frm.set_query("reference_name", function (doc) { + let filters = { docstatus: ["!=", 2] }; + + if (doc.company) { + filters["company"] = doc.company; + } + return { - filters: { - docstatus: ["!=", 2], - }, + filters: filters, }; }); diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.json b/erpnext/stock/doctype/quality_inspection/quality_inspection.json index 56017c4fee2..ebedd5b864b 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.json +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.json @@ -8,14 +8,14 @@ "engine": "InnoDB", "field_order": [ "naming_series", + "company", "report_date", "status", - "manual_inspection", + "child_row_reference", "column_break_4", "inspection_type", "reference_type", "reference_name", - "child_row_reference", "section_break_7", "item_code", "item_serial_no", @@ -27,6 +27,7 @@ "bom_no", "specification_details", "quality_inspection_template", + "manual_inspection", "readings", "section_break_14", "inspected_by", @@ -248,6 +249,12 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company" } ], "icon": "fa fa-search", @@ -255,7 +262,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2024-12-30 19:08:16.611192", + "modified": "2025-01-16 17:00:48.774532", "modified_by": "Administrator", "module": "Stock", "name": "Quality Inspection", diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index d3b5e65ea9f..1eb565b5338 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -30,6 +30,7 @@ class QualityInspection(Document): batch_no: DF.Link | None bom_no: DF.Link | None child_row_reference: DF.Data | None + company: DF.Link | None description: DF.SmallText | None inspected_by: DF.Link inspection_type: DF.Literal["", "Incoming", "Outgoing", "In Process"] @@ -76,6 +77,13 @@ class QualityInspection(Document): self.validate_inspection_required() self.set_child_row_reference() + self.set_company() + + def set_company(self): + if self.reference_type and self.reference_name: + company = frappe.get_cached_value(self.reference_type, self.reference_name, "company") + if company != self.company: + self.company = company def set_child_row_reference(self): if self.child_row_reference: