I’m trying to filter doctype Item list view to show only non template and not disabled items for non System Manager users. My custom script for Item doctype below is not working.
Custom Script will not filter your item list view. Above code will get executed when New / Existing Item form is opened. You have to try by server side logic.
You can try permission_query_conditions hook in your custom app.
Check how User listview is filtered.
permission_query_conditions = {
"Credit Control Process": "property_handover.property_handover.doctype.credit_control_process.credit_control_process.get_permission_query_conditions",
"Customer Service Processing": "property_handover.property_handover.doctype.customer_service_processing.customer_service_processing.get_permission_query_conditions",
}
has_permission = {
"Credit Control Process": "property_handover.property_handover.doctype.credit_control_process.credit_control_process.has_permission","Customer Service Processing": "property_handover.property_handover.doctype.customer_service_processing.customer_service_processing.has_permission",
}
after that add this in your py file
def get_permission_query_conditions(user):
if not user: user = frappe.session.user
if "Customer Service User" in frappe.get_roles(user):
u = frappe.db.sql("""select * from `tabProperty Handover Officers` where user_id=%s""",(frappe.session.user),as_dict=True)
return """(`tabCredit Control Process`.officer_name = '{current_sales_admin}' or `tabCredit Control Process`.officer_name = '{officer_name}')""".format(current_sales_admin=u.name, officer_name="")
def has_permission(doc):
u = frappe.db.sql("""select * from `tabProperty Handover Officers` where user_id=%s""",(frappe.session.user),as_dict=True)
if "Customer Service User" in frappe.get_roles(frappe.session.user) and (u.full_name==doc.officer_name or doc.officer_name==""):
return True
else:
return False