fix: do not send emails to disabled users from Employee Onboarding (#24795)

This commit is contained in:
Rohan
2021-03-09 21:03:45 +05:30
committed by GitHub
parent d7ac2394e8
commit db2d196296

View File

@@ -1,16 +1,19 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals import erpnext
import frappe, erpnext import frappe
from frappe import _
from frappe.utils import formatdate, format_datetime, getdate, get_datetime, nowdate, flt, cstr, add_days, today
from frappe.model.document import Document
from frappe.desk.form import assign_to
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
from frappe import _
from frappe.desk.form import assign_to
from frappe.model.document import Document
from frappe.utils import (add_days, cstr, flt, format_datetime, formatdate,
get_datetime, getdate, nowdate, today, unique)
class DuplicateDeclarationError(frappe.ValidationError): pass class DuplicateDeclarationError(frappe.ValidationError): pass
class EmployeeBoardingController(Document): class EmployeeBoardingController(Document):
''' '''
Create the project and the task for the boarding process Create the project and the task for the boarding process
@@ -48,27 +51,38 @@ class EmployeeBoardingController(Document):
continue continue
task = frappe.get_doc({ task = frappe.get_doc({
"doctype": "Task", "doctype": "Task",
"project": self.project, "project": self.project,
"subject": activity.activity_name + " : " + self.employee_name, "subject": activity.activity_name + " : " + self.employee_name,
"description": activity.description, "description": activity.description,
"department": self.department, "department": self.department,
"company": self.company, "company": self.company,
"task_weight": activity.task_weight "task_weight": activity.task_weight
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
activity.db_set("task", task.name) activity.db_set("task", task.name)
users = [activity.user] if activity.user else [] users = [activity.user] if activity.user else []
if activity.role: if activity.role:
user_list = frappe.db.sql_list('''select distinct(parent) from `tabHas Role` user_list = frappe.db.sql_list('''
where parenttype='User' and role=%s''', activity.role) SELECT
users = users + user_list DISTINCT(has_role.parent)
FROM
`tabHas Role` has_role
LEFT JOIN `tabUser` user
ON has_role.parent = user.name
WHERE
has_role.parenttype = 'User'
AND user.enabled = 1
AND has_role.role = %s
''', activity.role)
users = unique(users + user_list)
if "Administrator" in users: if "Administrator" in users:
users.remove("Administrator") users.remove("Administrator")
# assign the task the users # assign the task the users
if users: if users:
self.assign_task_to_users(task, set(users)) self.assign_task_to_users(task, users)
def assign_task_to_users(self, task, users): def assign_task_to_users(self, task, users):
for user in users: for user in users: