Issue with Company Filter

Good Day Everyone,

I am Using the Latest Version 11 of ERPNext, and I am using multiple Companies.
In HR Module, I noticed a few bugs concerning the Filtration of Companies.
At first, I noticed a bug in “Employee Transfer”,

When Updating the Department Field, it does not show only the Departments under the New Company, but shows all other Departments:

I have found bugs in “Leave Period” as well, when clicking on “Grant Leaves”.
Also in “Salary Structure Assignment” when clicking on “Assign To Employees”.
I am assigning Salary Structures and Granting Leaves Employee by Employee.
Please help me with this Issue ASAP.
Here’s The Issue on GitHub:
https://github.com/frappe/erpnext/issues/16858
Thank You.

Your problem that it is not filtering for the selected company?
If that is the case, then you can do this using custom script.

Regards
Bilal

@bghayad I am facing the same issue here!

If that is the case, then you can do this using custom script.

No, we can’t.

I tried to do that but found the code vary dynamic and complex.
Could you help us on this?

In which doctype you tried to do this and what field you were need to filter it based on the company?

Regards
Bilal

my case is I have multiple company and I want to transfer the employee from one company to another.
when I select property “Department” it will list all departments from all companies!

OK, at setup or at onload in the javascript file, you can use the below (as example):

        frm.set_query("department", function(doc) {
                return {
                        filters: {
                                'company': frm.doc.company
                        }
                };
        });

set_query is used to filter the field based on another field. Also you can have little bit advanced filters as the following example:

  • This filter will work based on multiple AND condition:

          frm.set_query("receivable_account", function(doc) {
                  return {
                          filters: {
                                  'account_type': 'Receivable',
                                  'is_group': 0,
                                  'company': frm.doc.company
                          }
                  };
          });
    
  • This filter will work based on the returned query values from the customer_query method:

          frm.set_query('customer', function(doc) {
                  return {
                          query: "erpnext.controllers.queries.customer_query"
                  };
          });
    
  • This filter will work based on the returned query value of the address_query method and based on the filters condition that is used for dynamic links:

          frm.set_query("address_title", function(doc) {
                  return {
                          query: 'frappe.contacts.doctype.address.address.address_query',
                          filters: {
                                  link_doctype: 'Customer',
                                  link_name: frm.doc.customer
                          }
                  }
          });
    

Regards
Bilal