Select default Leave Approver

76 views
Skip to first unread message

MP

unread,
Mar 8, 2013, 7:32:17 AM3/8/13
to erpnext-dev...@googlegroups.com

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur

Anand Doshi

unread,
Mar 8, 2013, 8:58:28 AM3/8/13
to erpnext-dev...@googlegroups.com
You can use user properties

Go to setup > profile > desires profile. Click on user properties button and add a user property "leave_approver" with value as the manager's user id. 

I think it should work. 

Sent from my phone
--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/8_k8NNCLZgMJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Message has been deleted

Rushabh Mehta

unread,
Mar 11, 2013, 5:47:12 AM3/11/13
to erpnext-dev...@googlegroups.com
Mayur, 

you can query the manager using a query to "webnotes.client.get_value" (see custom script example).

And if the returned value is present in the options (cur_frm.get_field("leave_approver").df.options) then you can use cur_frm.set_value("leave_approver", value) to set the value in the form.

You will have to piece these together from examples on the client script wiki page.

Also please post your solution here.

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 11-Mar-2013, at 3:11 PM, MP <mayur....@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.

MP

unread,
Mar 11, 2013, 5:49:30 AM3/11/13
to erpnext-dev...@googlegroups.com
Hi Anand,

Under Property drop-down list, there is no option for leave_approver. Is it possible to create new property called leave_approver? if not, how do we handle my issue?

Mayur


On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

MP

unread,
Mar 19, 2013, 8:24:44 AM3/19/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,

I am stuck and need a little bit of help here.

I am trying to get the User_id of an employee who is a manager of selected employee. Using "webnotes.client.get_value" I can get the Reports_to detail for selected employee but how do I get the user_id of the Report_to employee? Do I need to call webnotes.client.get_value method twice. Any help will be appreciated. Thank.


Mayur

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Anand Doshi

unread,
Mar 19, 2013, 8:26:40 AM3/19/13
to erpnext-dev...@googlegroups.com
Hi Mayur,

A simpler solution would be to write add fetch on Reports To so that the report to user's profile is fetched for the underling.

Then, use get_value only once to fetch the reports_to_id :)

Thanks,
Anand.

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.

MP

unread,
Mar 19, 2013, 8:38:45 AM3/19/13
to erpnext-dev...@googlegroups.com

Hi Anand,

What do you mean by add fetch on report_to. Is there any function called add_fetch that I can call?


Mayur
On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Anand Doshi

unread,
Mar 19, 2013, 8:44:00 AM3/19/13
to erpnext-dev...@googlegroups.com
Sorry for causing confusion. Here is the link:

Adding this script will cause a field in a linked document to be fetched, when a link field value is updated.

So, in employee form, you can set:
cur_frm.add_fetch('employee','user_id','reports_to_user_id')
reports_to_user_id being a custom field.

This will save the user id of the reporting manager in the employee's form.

Now you only need to use get_value once for the leave application page and get reports_to_user_id :)

Thanks,
Anand.



--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.

MP

unread,
Mar 20, 2013, 6:38:00 AM3/20/13
to erpnext-dev...@googlegroups.com
Hi Anand,

I am sorry if I am taking lot of your time but it didn't work. This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified employee.js file and added a new line for cur_frm.add_fetch('employee','user_id','reports_to_user_id')
- After that I clicked on Tools --> Clear Cache & Refresh
- Then I clicked on HR--> Employee --> one of the employee
- Selected an employee as  Reports To.
- clicked save.
- i checked the value for reports_to_user_id in database and also in web using web console and it is showing null.

Am I missing something?

regards,
Mayur Patel


On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Rushabh Mehta

unread,
Mar 20, 2013, 6:45:36 AM3/20/13
to erpnext-dev...@googlegroups.com
Mayur,

You have to add the add_fetch method in Custom Script the target doctype (Leave Application) not source


Also, the sequence of parameters is link, source, target

So it should be:

cur_frm.add_fetch('employee', 'reports_to_user_id', 'user_id')

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.

MP

unread,
Mar 20, 2013, 7:10:33 AM3/20/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,


This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified leave_application.js file and added a new line for cur_frm.add_fetch('employee','reports_to_user_id','user_id')
- After that I clicked on Tools --> Clear Cache & Refresh
- when i tries to access cur_frm.doc.user_id or cur_frm.doc.reports_to_user_id it is coming as undefined.

How do reports_to_user_id suppose to get populated in the database?

I don't think I really understand how this is suppose to work.

regards,
Mayur Patel



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Rushabh Mehta

unread,
Mar 20, 2013, 7:19:01 AM3/20/13
to erpnext-dev...@googlegroups.com
Mayur,

add_fetch is a javascript function and will only work on change of the employee field in the Leave Application form.

I think the problem for you is that the employee field is auto-selected (by default) so the change trigger may not work... Let me see if we can fix this for new forms. Can you confirm if it works when you change the employee value?

For older records, you will have to write a database (update) query.

Another (more elegant) solution is that in the employee.py,, just add a new default called "reports_to" so where-ever the reports to field is there in the form, it will auto-update by defaults... (https://github.com/webnotes/erpnext/blob/master/hr/doctype/employee/employee.py#L70). 
This way you can also use in other forms like Expense Claim for example.

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.

MP

unread,
Mar 20, 2013, 7:44:37 AM3/20/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,

I am logged in as Administrator. So by default, employee is not selected. But it still doesn't work when I select an employee. So basically it is not working. One thing I forgot to mention that reports_to_user_id is defined as Hidden field for employee doctype. Not sure if this matters?

I can update the old records manually but I am interested in knowing how the value for reports_to_user_id will get populated in the database?

As per your suggestion about elegant solution, are you saying that I need to add webnotes.conn.set_default("reports_to", self.doc.report_to, self.doc.user_id in def update_user_default(self): of employee.py? what does this do?

Mayur



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Rushabh Mehta

unread,
Mar 20, 2013, 7:56:20 AM3/20/13
to erpnext-dev...@googlegroups.com
Mayur,

Hi Rushabh,

I am logged in as Administrator. So by default, employee is not selected. But it still doesn't work when I select an employee. So basically it is not working.

Do you see anything in your error console? Is the employee name getting selected?

One thing I forgot to mention that reports_to_user_id is defined as Hidden field for employee doctype. Not sure if this matters?

Should not matter

I can update the old records manually but I am interested in knowing how the value for reports_to_user_id will get populated in the database?

Just as employee name is set when employee is selected.

As per your suggestion about elegant solution, are you saying that I need to add webnotes.conn.set_default("reports_to", self.doc.report_to, self.doc.user_id in def update_user_default(self): of employee.py? what does this do?

Yes this will make a "default value" for "reports_to" -- so where "reports_to" field appears, this will be set as the value. I would recommend this solution.

Mayur


On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?



--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages