snv
March 29, 2017, 1:38pm
#1
frappe.ui.form.on("Sales Invoice", "onload", function(frm) {
cur_frm.set_query("customer", function() {
return {
"filters": {
"customer_group": "Loans and Advances",
}
};
});
});
Ideally, above script should result in Sales Invoice showing customers of Loans and Advances group only. But the same does not work. I tried calling it on refresh too, but that does not work either.
try it like this (outside frappe.ui.form.on
):
this.frm.set_value("base_change_amount", 0.0);
}
this.frm.refresh_fields();
},
loyalty_amount: function(){
console.log("triggered the loyalty amount");
this.calculate_outstanding_amount();
this.frm.refresh_field("outstanding_amount");
this.frm.refresh_field("paid_amount");
this.frm.refresh_field("base_paid_amount");
}
});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_frm}));
// Hide Fields
// ------------
cur_frm.cscript.hide_fields = function(doc) {
1 Like
snv
March 29, 2017, 3:10pm
#3
Thanks for the reply.
cur_frm.set_query("customer", function() {
return {
filters: {
'customer_group': 'Loans and Advances',
}
}
});
I made the following changes:
removed quotes from ‘filters’ key
removed frappe.ui.form.on
It still shows the default query only.
Hi, I think you should try something like this
cur_frm.fields_dict['customer'].get_query = function(doc, cdt, cdn) { return{ query: "your_app.queries.get_customer_name", filters: {'customer_group': 'Loans ans Advances'} } }
and write python script get_customer_name
1 Like
snv
March 29, 2017, 5:18pm
#5
I spent a lot of time trying to figure out what’s wrong. Here’s what worked:
frappe.ui.form.on("Sales Invoice", "refresh", function(frm) {
cur_frm.set_query("customer", function() {
return {
query: "myappname.queries.customer.customer_query",
filters: [
["Customer", "customer_group", "!=", "Loan to Staff" ],
["Customer", "customer_group", "!=", "Loans and Advances" ],
],
}
});
});
Now I get the list of customers not in the groups pertaining to loan as they are not for invoice purposes.
What was wrong:
customer query in queries.js does not accept any filters (unlike item)
frappe.provide("erpnext.queries");
$.extend(erpnext.queries, {
user: function() {
return { query: "frappe.core.doctype.user.user.user_query" };
},
lead: function() {
return { query: "erpnext.controllers.queries.lead_query" };
},
customer: function() {
return { query: "erpnext.controllers.queries.customer_query" };
},
supplier: function() {
return { query: "erpnext.controllers.queries.supplier_query" };
},
item: function(filters) {
var args = { query: "erpnext.controllers.queries.item_query" };
if(filters) args["filters"] = filters;
customer query in queries.py does not send filters in mysql query:
if cust_master_name == "Customer Name":
fields = ["name", "customer_group", "territory"]
else:
fields = ["name", "customer_name", "customer_group", "territory"]
meta = frappe.get_meta("Customer")
searchfields = meta.get_search_fields()
searchfields = searchfields + [f for f in [searchfield or "name", "customer_name"] \
if not f in searchfields]
fields = fields + [f for f in searchfields if not f in fields]
fields = ", ".join(fields)
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
return frappe.db.sql("""select {fields} from `tabCustomer`
where docstatus < 2
and ({scond}) and disabled=0
{fcond} {mcond}
order by
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
Hi can you guide me i am not able to do the same please
Hi all,
this seems to still be an issue. I am trying to filter a customer link field using
refresh: function(frm) {
cur_frm.fields_dict['customer'].get_query = function() {
return {
filters: { 'disabled': 0 }
}
}
}
All other filters work nicely but this has no effect as described in this thread. Has this ever been addressed?
Created a GitHub issue: https://github.com/frappe/erpnext/issues/15876