How do I add filters so that I can group employees as per reporting to their respective manager?? Please help I am new to erpnext
Where do you want to add filters please elaborate more.
I want to add filter as “sales manager” such that when I select a sales manager I get the sales person reporting to respective sales manager as well as the sales order details prepared by the sales person. I want to add these filters in report.
On which report? Is it standard report or script report?
Its a script report. I am not getting any output.Please help
#Below is my JS filter code
frappe.query_reports["Reports For Sales Manager Based On Team"] = {
"filters": [
{
'label': __("Reports To"),
'fieldname': 'employee',
'fieldtype': 'Link',
'options': 'Sales Person',
'default': 'Select Reporting Manager',
'reqd': 1
}
]
}
#Below is my python code
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils
def execute(filters=None):
if not filters: filters = {}
columns = get_columns()
data = get_sales_order(filters)
return columns, data
def get_columns():
return [
_("Sales Person") + ":Data:120", _("Name") + ":Link/Sales Order:120",
_("Company") + ":Data:200", _("customer") + ":Link/Customer:350"
]
def get_sales_order(filters):
conditions = get_conditions(filters)
return frappe.db.sql("""Select sales_person, name, employee_name, company, customer
from tabSales Order where status != 'Cancelled'""" %conditions, as_list=1)
def get_conditions(filters):
conditions = ""
if filters.get("reports_to"):
reports_to = ["Hars Pathak", "Anan Chakraborty", "Rahul Kaushal"].index(filters["reports_to"]) + 1
conditions += "and reports_to(employee) = '%s'" % reports_to
return conditions
You can add a custom filter on .js file.
frappe.query_reports[“Your report name”] = {
“filters”: [
{
“fieldname”:“sales_manager”,
“label”: __(“Sales Manager”),
“fieldtype”: “Link”,
“options”: “User”,
get_query:function() {
return {
“query”:“your path to query”
}
},
},
]
}
You have to return a query by filtering user as per role as sales manager