Good morning,
per default, any user who belong to group HR Officer will be able to approve leave requests for anybody;
this is done by setting a group in the corresponding workflow transition (from state confirm to state validate in hr.wkf.holidays).
What we will do to achieve our goal is :
- creating a new group;
- creating a function to check if the officer is about to validate is own request.
- changing the condition to validate the transition.
1/ Create the group :
- Name : Can't Approve own leaves (or whatever you need)
- Application : HR
2/ create the function :
- add the following code to the hr_holidays.py file
def is_officer_employee(self, cr, uid, ids, *args):
for leave in self.browse(cr, uid, ids):
if uid==leave.employee_id.user_id.id:
return True
else:
return False
This code has to be in the class hr_holidays
- delete the hr_holidays.pyc file
- restart your server with option --update=hr_holidays
3/ Modify the workflow
- The easiest way to do it is to go in Settings \ Configuration \ Worflows \ Workflows and edit hr.wkf.holidays in diagram view
- double clic on the transition
- change the condition from "not double_validation" to "not double_validation and not is_officer_employee()"
- change the Group Required from "Human Resources / Officer" to "Human Resources / Can't Approve own leaves"
4/ Test
- don't use admin user since it has special rights
- don't forget to add your user to both groups Officer and Can't Approve own leaves.
Marc.
PS: please vote if you find it helpful.