How to applied permanent filter in list view

I want to view list view according to condition and query set by myself every time when list view is rendered. Please someone help me with.

Hi @niraj_regmi,

We did apply on default filter in Sales Order Lisview.
When the user reloads the page, then automatically applies the filter.

We did apply the default filter for status.

Please apply the client script for Listview.

frappe.listview_settings['Sales Order'] = {
    onload : function(listview) {
        frappe.route_options = {
            "status": "Draft"
          };
        listview.refresh();
    }
};

Output:

Please set your doctype and field name according to the script.
I hope this help.

Thank You!

1 Like

This temporary if user clears the filter then the filter will gone. I need that filter to be permanent.

You need to modify list query using custom app.
You can customize how list of records are queried for a DocType by adding custom match conditions using the permission_query_conditions hook. This match condition must be a valid WHERE clause fragment for an SQL query.

app/hooks.py

permission_query_conditions = {
    "ToDo": "app.permissions.todo_query",
}

app/permissions.py

def todo_query():
    return "(`tabToDo`.status = 'Open')"

The above code will modify the query to only display status with ‘Open’ in Todo doctype.
You can even apply this to specific users and roles.
For more details refer documentation

1 Like

Is there a way to selet a field in the filtrer than as we type the items get selected automatically like a dynamic result from a search button? i realize some items has that by default like item code, others don’t…

I have tried this but the list is not populating as per our conditions.

Link fields are automatically displayed like that.

That’s the only way as per my understanding.
Post your full code or requirement, may be we can try a bit.

do you know where we can change that?

I am a Timesheet Approver for my team and under my team there are 5 members lets say. So what I want is in my list of timesheet i should only have permission to view the timesheet of those 5 members only. And also if the timesheet is in the state of “Pending Approval from Manager”. I have restrict the timesheet of 5 members from user permission by giving the employee permission of 5 members now i can see those members timesheet only but the problem is with the state of timesheet, i have to see the timesheet which are in pending state but i can see their draft state timesheet also. So i need to populate the timesheet list which are in pending state of those 5 members only and should able to approve those timesheet only.

permission_query_conditions = {
    "ToDo": "app.permissions.todo_query",
}

app/permissions.py

def todo_query():
    return "(`tabToDo`.status = 'Open' ) And (`tabTodo`.workflow_state = 'pending')"

like this you can also add in a condition for tabTodo.workflow_state = ‘pending’

Any hints/examples on using permission_query_conditions on capabilities other than SELECT or LISTVIEW?

Specifically, I am trying to mix between Role Perssmsion (i.e., DELETE) and User Permission (i.e., when Department == Sales).