ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Issue with Company Filter

hr

#1

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:


Thank You.


#2

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


#3

@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?


#4

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

Regards
Bilal


#5

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!


#6

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