fix: move average calculation to interview controller
This commit is contained in:
parent
69eb3a0ac9
commit
d96f4bf628
@ -7,7 +7,7 @@ import datetime
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cstr, get_datetime, get_link_to_form
|
from frappe.utils import cstr, flt, get_datetime, get_link_to_form
|
||||||
|
|
||||||
|
|
||||||
class DuplicateInterviewRoundError(frappe.ValidationError):
|
class DuplicateInterviewRoundError(frappe.ValidationError):
|
||||||
@ -18,6 +18,7 @@ class Interview(Document):
|
|||||||
self.validate_duplicate_interview()
|
self.validate_duplicate_interview()
|
||||||
self.validate_designation()
|
self.validate_designation()
|
||||||
self.validate_overlap()
|
self.validate_overlap()
|
||||||
|
self.set_average_rating()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.status not in ['Cleared', 'Rejected']:
|
if self.status not in ['Cleared', 'Rejected']:
|
||||||
@ -67,6 +68,13 @@ class Interview(Document):
|
|||||||
overlapping_details = _('Interview overlaps with {0}').format(get_link_to_form('Interview', overlaps[0][0]))
|
overlapping_details = _('Interview overlaps with {0}').format(get_link_to_form('Interview', overlaps[0][0]))
|
||||||
frappe.throw(overlapping_details, title=_('Overlap'))
|
frappe.throw(overlapping_details, title=_('Overlap'))
|
||||||
|
|
||||||
|
def set_average_rating(self):
|
||||||
|
total_rating = 0
|
||||||
|
for entry in self.interview_details:
|
||||||
|
if entry.average_rating:
|
||||||
|
total_rating += entry.average_rating
|
||||||
|
|
||||||
|
self.average_rating = flt(total_rating / len(self.interview_details) if len(self.interview_details) else 0)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def reschedule_interview(self, scheduled_on, from_time, to_time):
|
def reschedule_interview(self, scheduled_on, from_time, to_time):
|
||||||
|
@ -57,7 +57,6 @@ class InterviewFeedback(Document):
|
|||||||
|
|
||||||
def update_interview_details(self):
|
def update_interview_details(self):
|
||||||
doc = frappe.get_doc('Interview', self.interview)
|
doc = frappe.get_doc('Interview', self.interview)
|
||||||
total_rating = 0
|
|
||||||
|
|
||||||
if self.docstatus == 2:
|
if self.docstatus == 2:
|
||||||
for entry in doc.interview_details:
|
for entry in doc.interview_details:
|
||||||
@ -72,10 +71,6 @@ class InterviewFeedback(Document):
|
|||||||
entry.comments = self.feedback
|
entry.comments = self.feedback
|
||||||
entry.result = self.result
|
entry.result = self.result
|
||||||
|
|
||||||
if entry.average_rating:
|
|
||||||
total_rating += entry.average_rating
|
|
||||||
|
|
||||||
doc.average_rating = flt(total_rating / len(doc.interview_details) if len(doc.interview_details) else 0)
|
|
||||||
doc.save()
|
doc.save()
|
||||||
doc.notify_update()
|
doc.notify_update()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user