diff --git a/erpnext/education/doctype/question/question.py b/erpnext/education/doctype/question/question.py index 28d3ecdf8c3..57d8de4d651 100644 --- a/erpnext/education/doctype/question/question.py +++ b/erpnext/education/doctype/question/question.py @@ -4,10 +4,28 @@ from __future__ import unicode_literals import frappe +from frappe import _ from frappe.model.document import Document class Question(Document): + def validate(self): + self.check_at_least_one_option() + self.check_minimum_one_correct_answer() + + def check_at_least_one_option(self): + if len(self.get_all_children()) <= 1: + frappe.throw(_("A question must have more than one options")) + else: + pass + + def check_minimum_one_correct_answer(self): + correct_options = [question.is_correct for question in self.get_all_children()] + if bool(sum(correct_options)): + pass + else: + frappe.throw(_("A qustion must have at least one correct options")) + def get_answer(self): options = self.get_all_children() answers = [item.name for item in options if item.is_correct == True]