'Checks if quality inspection is set for Items that require inspection.
On submit, throw an exception'

def validate_inspection(self):

    inspection_required_fieldname = None
    if (self.doctype in [u'Purchase    Receipt', u'Purchase    Invoice']):
        inspection_required_fieldname = u'inspection_required_before_purchase'
    elif (self.doctype in [u'Delivery    Note', u'Sales    Invoice']):
        inspection_required_fieldname = u'inspection_required_before_delivery'
    if ((not inspection_required_fieldname) or ((self.doctype in [u'Sales    Invoice', u'Purchase    Invoice']) and (not self.update_stock))):
        return
    for d in self.get(u'items'):
        if (frappe.db.get_value(u'Item', d.item_code, inspection_required_fieldname) and (not d.quality_inspection)):
            frappe.msgprint(_(u'Quality    Inspection    required    for    Item    {0}').format(d.item_code))
            if (self.docstatus == 1):
                raise frappe.ValidationError
