Hello!
I need to change lists of user permissions when I creating Emloyee.
By default afer click on this checkbox erpnext creating 2 permissions based on Complany and Employee.
I need to add value based on Department.
Hello!
I need to change lists of user permissions when I creating Emloyee.
By default afer click on this checkbox erpnext creating 2 permissions based on Complany and Employee.
I need to add value based on Department.
Do you want to add department along with company and employee?
yes and some other options. But Department firstly.
That for, you have to apply the server script on ‘after_save’.
if doc.create_user_permission:
employee_user_permission_exists = frappe.db.exists(
"User Permission", {"allow": "Employee", "for_value": doc.name, "user": doc.user_id}
)
if not employee_user_permission_exists:
user_permission = frappe.get_doc({
"doctype": "User Permission",
"user": doc.user_id,
"allow": "Employee",
"for_value": doc.name,
"apply_to_all_doctypes": False
})
user_permission.insert(ignore_permissions=True)
company_user_permission_exists = frappe.db.exists(
"User Permission", {"allow": "Company", "for_value": doc.company, "user": doc.user_id}
)
if not company_user_permission_exists:
user_permission = frappe.get_doc({
"doctype": "User Permission",
"user": doc.user_id,
"allow": "Company",
"for_value": doc.company,
"apply_to_all_doctypes": False
})
user_permission.insert(ignore_permissions=True)
department_user_permission_exists = frappe.db.exists(
"User Permission", {"allow": "Department", "for_value": doc.department, "user": doc.user_id}
)
if not department_user_permission_exists and doc.department:
user_permission = frappe.get_doc({
"doctype": "User Permission",
"user": doc.user_id,
"allow": "Department",
"for_value": doc.department,
"apply_to_all_doctypes": False
})
user_permission.insert(ignore_permissions=True)
Output: