[solved] Why this filter not working

This filter does not work. It will always display all the customer even I put this filter. I already tried to reload. There is no error in JS Console. Any idea why?

frappe.ui.form.on("Payment", "onload", function(frm) {

    cur_frm.set_query("customer", function() {
        return {
            "filters": {
                "customer_group": 'Tenant'
            }
        };
    });
});

@rmehta @anand as I dig deeper I have found out that when a field is link to a customer doctyype it will used a standard query which is erpnext.selling.doctype.customer.customer.get_customer_list and when I look at get_customer_list erpnext/customer.py at develop · frappe/erpnext · GitHub

filter parameter is not used. Is this intentional? How will I filter a link column to a customer doctype?

def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
	if frappe.db.get_default("cust_master_name") == "Customer Name":
		fields = ["name", "customer_group", "territory"]
	else:
		fields = ["name", "customer_name", "customer_group", "territory"]

	match_conditions = build_match_conditions("Customer")
	match_conditions = "and {}".format(match_conditions) if match_conditions else ""

	return frappe.db.sql("""select %s from `tabCustomer` where docstatus < 2
		and (%s like %s or customer_name like %s)
		{match_conditions}
		order by
		case when name like %s then 0 else 1 end,
		case when customer_name like %s then 0 else 1 end,
		name, customer_name limit %s, %s""".format(match_conditions=match_conditions) %
		(", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
		("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))

I ended up creating my own query

frappe.ui.form.on("Payment", {
	onload: function(frm) {
		frm.set_query("customer", function() {
			return {
				query: "residences.residences.doctype.payment.payment.get_active_tenant"
			};
		});
    }
});

and then I just hard coded the where clause customer_group = 'Tenant' in get_active_tenant.

@ccfiel

query: “residences.residences.doctype.payment.payment.get_active_tenant”

i understand
1 residences is AppName
2 residences is module name
3 doctype for doctype reference
4 payment is doctype
5 payment is fieldname (?)
6 get_active_tenant — I CAN NOT UNDERSTAND IT.
(how get_active_tenant to be define)

i got partial idea from your refernce :
erpnext.selling.doctype.customer.customer.get_customer_list

Please give detail explaination as it is very useful for all…

Thanks in advance

get_active_tenant is a method name at py side which consist your query and call this method at js side which return value to respective field.

Hi, want to do the same thing but not able to do it ?? can you help me