add custom field department to doctype Lead via either customize form
Assign department in lead by authorized user
add the highlighted lines to your custom app’s hooks.py file
also add the following function codes into relevant py file, e.g api.py under the module folder of the custom app
here the code for copy and adapt.
from __future__ import unicode_literals
import frappe
def get_permission_query_conditions(user):
if not user: user = frappe.session.user
roles = [r for r in frappe.get_roles() if r in ['Sales Manager','System Manager']]
if roles:
return ""
else:
return """(department = (select department from `tabEmployee` where user_id=%(user)s limit 1)
or owner=%(user)s)""" % {
"user": frappe.db.escape(user),
}
def has_permission(doc, user):
if not user: user = frappe.session.user
roles = [r for r in frappe.get_roles() if r in ['Sales Manager','System Manager']]
department = frappe.db.get_value('Employee',{'user_id': user}, 'department')
if roles or doc.owner==user or doc.department==department:
return True
return False
to be clarified further.
here the similar post for reference Hook has_permission + permission function on docType - #11 by szufisher



