feat: sending Exit Questionnaire
This commit is contained in:
parent
36a2d8ee0d
commit
7412accf6d
@ -3,12 +3,16 @@
|
||||
|
||||
frappe.ui.form.on('Exit Interview', {
|
||||
refresh: function(frm) {
|
||||
|
||||
if (!frm.doc.__islocal && !frm.doc.questionnaire_email_sent) {
|
||||
frm.add_custom_button(__('Send Exit Questionnaire'), function () {
|
||||
frm.trigger('send_exit_questionnaire');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
employee: function(frm) {
|
||||
frappe.db.get_value('Employee', frm.doc.employee, 'relieving_date').then(({ relieving_date }) => {
|
||||
if (!relieving_date) {
|
||||
frappe.db.get_value('Employee', frm.doc.employee, 'relieving_date', (message) => {
|
||||
if (!message.relieving_date) {
|
||||
frappe.throw({
|
||||
message: __('Please set the relieving date for employee {0}',
|
||||
['<a href="/app/employee/' + frm.doc.employee +'">' + frm.doc.employee + '</a>']),
|
||||
@ -16,5 +20,33 @@ frappe.ui.form.on('Exit Interview', {
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
send_exit_questionnaire: function(frm) {
|
||||
frappe.db.get_value('HR Settings', 'HR Settings',
|
||||
['exit_questionnaire_web_form', 'exit_questionnaire_notification_template'], (r) => {
|
||||
if (!r.exit_questionnaire_web_form || !r.exit_questionnaire_notification_template) {
|
||||
frappe.throw({
|
||||
message: __('Please set {0} and {1} in {2}.',
|
||||
['Exit Questionnaire Web Form'.bold(),
|
||||
'Notification Template'.bold(),
|
||||
'<a href="/app/hr-settings" target="_blank">HR Settings</a>']
|
||||
),
|
||||
title: __('Settings Missing')
|
||||
});
|
||||
} else {
|
||||
frappe.call({
|
||||
method: 'erpnext.hr.doctype.exit_interview.exit_interview.send_exit_questionnaire',
|
||||
args: {
|
||||
'exit_interview': frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
if (!r.exc) {
|
||||
frm.refresh_field('questionnaire_email_sent');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -5,11 +5,13 @@
|
||||
"creation": "2021-12-05 13:56:36.241690",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"email_append_to": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"naming_series",
|
||||
"employee",
|
||||
"employee_name",
|
||||
"email",
|
||||
"column_break_5",
|
||||
"company",
|
||||
"date",
|
||||
@ -22,6 +24,7 @@
|
||||
"relieving_date",
|
||||
"exit_questionnaire_section",
|
||||
"ref_doctype",
|
||||
"questionnaire_email_sent",
|
||||
"column_break_10",
|
||||
"reference_document_name",
|
||||
"interview_summary_section",
|
||||
@ -130,6 +133,7 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "employee.reports_to",
|
||||
"fieldname": "reports_to",
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
@ -159,11 +163,25 @@
|
||||
"fieldtype": "Select",
|
||||
"label": "Naming Series",
|
||||
"options": "HR-EXIT-INT-"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "questionnaire_email_sent",
|
||||
"fieldtype": "Check",
|
||||
"label": "Questionnaire Email Sent",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "email",
|
||||
"fieldtype": "Data",
|
||||
"label": "Email ID",
|
||||
"options": "Email",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-12-05 14:25:40.416023",
|
||||
"modified": "2021-12-05 16:50:05.933394",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Exit Interview",
|
||||
@ -183,6 +201,7 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sender_field": "email",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "employee_name",
|
||||
|
@ -6,12 +6,48 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import get_link_to_form
|
||||
|
||||
from erpnext.hr.doctype.employee.employee import get_employee_email
|
||||
|
||||
|
||||
class ExitInterview(Document):
|
||||
def validate(self):
|
||||
self.validate_relieving_date()
|
||||
self.set_employee_email()
|
||||
|
||||
def validate_relieving_date(self):
|
||||
if not frappe.db.get_value('Employee', self.employee, 'relieving_date'):
|
||||
frappe.throw(_('Please set the relieving date for employee {0}').format(
|
||||
get_link_to_form('Employee', self.employee)),
|
||||
title=_('Relieving Date Missing'))
|
||||
|
||||
def set_employee_email(self):
|
||||
employee = frappe.get_doc('Employee', self.employee)
|
||||
self.email = get_employee_email(employee)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_exit_questionnaire(exit_interview):
|
||||
exit_interview = frappe.get_doc('Exit Interview', exit_interview)
|
||||
context = exit_interview.as_dict()
|
||||
|
||||
employee = frappe.get_doc('Employee', exit_interview.employee)
|
||||
context.update(employee.as_dict())
|
||||
|
||||
email = get_employee_email(employee)
|
||||
template_name = frappe.db.get_single_value('HR Settings', 'exit_questionnaire_notification_template')
|
||||
template = frappe.get_doc('Email Template', template_name)
|
||||
|
||||
if email:
|
||||
frappe.sendmail(
|
||||
recipients=email,
|
||||
subject=template.subject,
|
||||
message=frappe.render_template(template.response, context),
|
||||
reference_doctype=exit_interview.doctype,
|
||||
reference_name=exit_interview.name
|
||||
)
|
||||
frappe.msgprint(_('Exit Questionnaire sent to {0}').format(email),
|
||||
title='Success', indicator='green')
|
||||
exit_interview.db_set('questionnaire_email_sent', True)
|
||||
exit_interview.notify_update()
|
||||
else:
|
||||
frappe.msgprint(_('Email IDs for employee not found.'))
|
@ -36,7 +36,11 @@
|
||||
"remind_before",
|
||||
"column_break_4",
|
||||
"send_interview_feedback_reminder",
|
||||
"feedback_reminder_notification_template"
|
||||
"feedback_reminder_notification_template",
|
||||
"employee_exit_section",
|
||||
"exit_questionnaire_web_form",
|
||||
"column_break_34",
|
||||
"exit_questionnaire_notification_template"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@ -226,13 +230,34 @@
|
||||
"fieldname": "check_vacancies",
|
||||
"fieldtype": "Check",
|
||||
"label": "Check Vacancies On Job Offer Creation"
|
||||
},
|
||||
{
|
||||
"fieldname": "employee_exit_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Employee Exit Settings"
|
||||
},
|
||||
{
|
||||
"fieldname": "exit_questionnaire_web_form",
|
||||
"fieldtype": "Link",
|
||||
"label": "Exit Questionnaire Web Form",
|
||||
"options": "Web Form"
|
||||
},
|
||||
{
|
||||
"fieldname": "exit_questionnaire_notification_template",
|
||||
"fieldtype": "Link",
|
||||
"label": "Exit Questionnaire Notification Template",
|
||||
"options": "Email Template"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_34",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-10-01 23:46:11.098236",
|
||||
"modified": "2021-12-05 14:48:10.884253",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "HR Settings",
|
||||
|
Loading…
x
Reference in New Issue
Block a user