List based on filters

Can I get list say salary slip list based on status (draft, cancelled etc) while loading data. Don’t want to show cancelled or drafted records to employees

Hi, @Pretty_Gupta

Yes, this is possible

import frappe

# Connect to the Frappe database

# Define the status to filter by
status = "Submitted"

# Retrieve the salary slips based on the status
salary_slips = frappe.get_all("Salary Slip", filters={"docstatus": 1, "status": status})

# Filter out the cancelled and drafted records
filtered_salary_slips = [slip for slip in salary_slips if slip.get("status") not in ["Draft", "Cancelled"]]

# Do something with the filtered salary slips
for slip in filtered_salary_slips:
    # Do something with each salary slip, e.g. display it to the employee

# Disconnect from the database

Hope this will help you out.
Thank you.

Thanks for the update. But in ERPNext it is controlled by listview settings injs files and we dont have anything in py files. Can you suggest me a way

You can set default filters in list JS

But that can be changed by user. Don’t want that user can change the filter for that