From 06ce1f5a403edc2f2073b93ae68eda73e4093d73 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 14 Aug 2019 14:25:59 +0530 Subject: [PATCH] fix(quality-inspection): fetch all items for inspection type in process (#18716) * fix(quality-inspection): fetch all items for inspection type in process * fix(quality-inspection): add server side validation for in process items --- .../quality_inspection/quality_inspection.js | 7 ++++--- .../quality_inspection/quality_inspection.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.js b/erpnext/stock/doctype/quality_inspection/quality_inspection.js index aa9854aee1..22f29e05b4 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.js +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.js @@ -39,11 +39,12 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query", filters: { "from": doctype, - "parent": doc.reference_name + "parent": doc.reference_name, + "inspection_type": doc.inspection_type } - } + }; } -} +}, // Serial No based on item_code cur_frm.fields_dict['item_serial_no'].get_query = function(doc, cdt, cdn) { diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index e0b738202c..4e42e70367 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import frappe +from frappe import _ from frappe.model.document import Document from erpnext.stock.doctype.quality_inspection_template.quality_inspection_template \ import get_template_details @@ -11,6 +12,7 @@ class QualityInspection(Document): def validate(self): if not self.readings and self.item_code: self.get_item_specification_details() + self.validate_inspection_type() def get_item_specification_details(self): if not self.quality_inspection_template: @@ -27,6 +29,14 @@ class QualityInspection(Document): child.value = d.value child.status = "Accepted" + def validate_inspection_type(self): + if self.inspection_type != "In Process": + inspection_required = frappe.db.get_value("Item", filters={ + 'name': self.item_code + }, fieldname=['inspection_required_before_purchase', 'inspection_required_before_delivery']) + if 0 in inspection_required: + frappe.throw(_('Inspection type for the item can only be in process.')) + def get_quality_inspection_template(self): template = '' if self.bom_no: @@ -63,10 +73,12 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): mcond = get_match_cond(filters["from"]) cond, qi_condition = "", "and (quality_inspection is null or quality_inspection = '')" - if filters.get('from') in ['Purchase Invoice Item', 'Purchase Receipt Item']: + if filters.get('from') 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 filters.get('from') in ['Sales Invoice Item', 'Delivery Note Item']: + elif filters.get('from') 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 filters.get('from') == 'Stock Entry Detail':