This question has been flagged
1 Reply
7515 Views

I wonder how can I prevent HR Managers from approving their own leave requests?

HR Managers requests must be approved by one of their colleagues.

However, I also must be able to tell openERP that certain managers are allowed to approve their own requests.

:|

Avatar
Discard
Best Answer

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.

Avatar
Discard

Can I use the same function to restrict HR Officer to approve their own leave ?

Hi, I tried your solution but not working for me. As per the step 2 I updated the code in hr_holiday.py file and deleted the hr_holiday.pyc. And when I restart the service (C:\Windows\system32>sc start openerp-server-7.0 --update=hr_holidays) the openERP site is not loading. I could see an error "No handler found." . And the hr_holidays.pyc file not generated after the service restart. Any help would be appreciable. OpenERP Version : 7.0-20130429-232454 , OS : Windows 7 64bit