Try ERPNext Buy Support Partners Foundation

[Closed] Sales Order: filter in the custom fields [Managing multiple companies in one instance]

Hello

I have created one custom field ‘Company’ wherever applicable to separate different companies i’m managing through one instance and then I apply user permission for company to restrict the access.
This custom field is also added in other DocType as well such as Item, Customers, Suppliers etc.

However, in case of the users who have no such restrictions, there are some issues regarding which I need some help:

  1. When i select the ‘Company A’ in the Sales Order, I expect the customer list to get filtered based on it. (as the same custom field is there in the Customer DocType too).

image

  1. But it lists out all the customers in the system irrespective of the company.

  2. On the contrary, it is automatically applied to Sales Taxes and Charges Template field in the sales order and it correctly shows the templates created for the respective company earlier selected.

Am I wrong somewhere in the approach or have I missed any important step?

Thanking you.

You can use get_query for the same

image

If operation is more that you want to perform at your end you can pass query parameter too so python endpoint will manipulate the data(your logic)

I used the following script:

frappe.ui.form.on(‘Sales Order’, {
company:function(frm) {
frm.set_query(‘customer’,function(){
return {
filters:{
‘company’:frm.doc.company
}
}
})
}
})