Browse Source

feat: bulk questionnaire sending

develop
Rucha Mahabal 3 years ago
parent
commit
e30187f246
  1. 16
      erpnext/hr/doctype/exit_interview/exit_interview.js
  2. 6
      erpnext/hr/doctype/exit_interview/exit_interview.json
  3. 72
      erpnext/hr/doctype/exit_interview/exit_interview.py
  4. 27
      erpnext/hr/doctype/exit_interview/exit_interview_list.js

16
erpnext/hr/doctype/exit_interview/exit_interview.js

@ -23,22 +23,10 @@ frappe.ui.form.on('Exit Interview', {
}, },
send_exit_questionnaire: function(frm) { 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({ frappe.call({
method: 'erpnext.hr.doctype.exit_interview.exit_interview.send_exit_questionnaire', method: 'erpnext.hr.doctype.exit_interview.exit_interview.send_exit_questionnaire',
args: { args: {
'exit_interview': frm.doc.name 'interviews': [frm.doc]
}, },
callback: function(r) { callback: function(r) {
if (!r.exc) { if (!r.exc) {
@ -47,6 +35,4 @@ frappe.ui.form.on('Exit Interview', {
} }
}); });
} }
});
}
}); });

6
erpnext/hr/doctype/exit_interview/exit_interview.json

@ -87,8 +87,7 @@
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Date", "label": "Date",
"mandatory_depends_on": "eval:doc.status==='Scheduled';", "mandatory_depends_on": "eval:doc.status==='Scheduled';"
"reqd": 1
}, },
{ {
"fieldname": "exit_questionnaire_section", "fieldname": "exit_questionnaire_section",
@ -174,6 +173,7 @@
"fieldtype": "Check", "fieldtype": "Check",
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Questionnaire Email Sent", "label": "Questionnaire Email Sent",
"no_copy": 1,
"read_only": 1 "read_only": 1
}, },
{ {
@ -218,7 +218,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2021-12-05 17:49:44.839277", "modified": "2021-12-05 18:56:34.856854",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Exit Interview", "name": "Exit Interview",

72
erpnext/hr/doctype/exit_interview/exit_interview.py

@ -38,14 +38,23 @@ class ExitInterview(Document):
@frappe.whitelist() @frappe.whitelist()
def send_exit_questionnaire(exit_interview): def send_exit_questionnaire(interviews):
exit_interview = frappe.get_doc('Exit Interview', exit_interview) interviews = get_interviews(interviews)
context = exit_interview.as_dict() validate_questionnaire_settings()
employee = frappe.get_doc('Employee', exit_interview.employee) email_success = []
context.update(employee.as_dict()) email_failure = []
for exit_interview in interviews:
interview = frappe.get_doc('Exit Interview', exit_interview.get('name'))
if interview.get('questionnaire_email_sent'):
continue
employee = frappe.get_doc('Employee', interview.employee)
email = get_employee_email(employee) email = get_employee_email(employee)
context = interview.as_dict()
context.update(employee.as_dict())
template_name = frappe.db.get_single_value('HR Settings', 'exit_questionnaire_notification_template') template_name = frappe.db.get_single_value('HR Settings', 'exit_questionnaire_notification_template')
template = frappe.get_doc('Email Template', template_name) template = frappe.get_doc('Email Template', template_name)
@ -54,12 +63,51 @@ def send_exit_questionnaire(exit_interview):
recipients=email, recipients=email,
subject=template.subject, subject=template.subject,
message=frappe.render_template(template.response, context), message=frappe.render_template(template.response, context),
reference_doctype=exit_interview.doctype, reference_doctype=interview.doctype,
reference_name=exit_interview.name reference_name=interview.name
) )
frappe.msgprint(_('Exit Questionnaire sent to {0}').format(email), interview.db_set('questionnaire_email_sent', True)
title='Success', indicator='green') interview.notify_update()
exit_interview.db_set('questionnaire_email_sent', True) email_success.append(email)
exit_interview.notify_update()
else: else:
frappe.msgprint(_('Email IDs for employee not found.')) email_failure.append(get_link_to_form('Employee', employee.name))
show_email_summary(email_success, email_failure)
def get_interviews(interviews):
import json
if isinstance(interviews, str):
interviews = json.loads(interviews)
if not len(interviews):
frappe.throw(_('Atleast one interview has to be selected.'))
return interviews
def validate_questionnaire_settings():
settings = frappe.db.get_value('HR Settings', 'HR Settings',
['exit_questionnaire_web_form', 'exit_questionnaire_notification_template'], as_dict=True)
if not settings.exit_questionnaire_web_form or not settings.exit_questionnaire_notification_template:
frappe.throw(
message=_('Please set {0} and {1} in {2}.').format(
frappe.bold('Exit Questionnaire Web Form'),
frappe.bold('Notification Template'),
get_link_to_form('HR Settings', 'HR Settings')),
title=_('Settings Missing')
)
def show_email_summary(email_success, email_failure):
message = ''
if email_success:
message += _('{0}: {1}').format(
frappe.bold('Sent Successfully'), ', '.join(email_success))
if email_failure:
message += + '<br><br>' + _('{0} due to missing email information for employee(s): {1}').format(
frappe.bold('Sending Failed'), ', '.join(email_failure))
frappe.msgprint(message, title=_('Exit Questionnaire'), indicator='blue', is_minimizable=True, wide=True)

27
erpnext/hr/doctype/exit_interview/exit_interview_list.js

@ -0,0 +1,27 @@
frappe.listview_settings['Exit Interview'] = {
has_indicator_for_draft: 1,
get_indicator: function(doc) {
let status_color = {
'Pending': 'orange',
'Scheduled': 'yellow',
'Completed': 'green',
'Cancelled': 'red',
};
return [__(doc.status), status_color[doc.status], 'status,=,'+doc.status];
},
onload: function(listview) {
if (frappe.boot.user.can_write.includes('Exit Interview')) {
listview.page.add_action_item(__('Send Exit Questionnaires'), function() {
const interviews = listview.get_checked_items();
frappe.call({
method: 'erpnext.hr.doctype.exit_interview.exit_interview.send_exit_questionnaire',
freeze: true,
args: {
'interviews': interviews
}
});
});
}
}
};
Loading…
Cancel
Save