Odoo Help


Prevent HR Managers from approving their own leave requests

Rui Franco
on 8/6/13, 11:50 AM 4,146 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.



Marc Cassuto

--Marc Cassuto--
Arche TI
| 4 5 8
Montreal, Canada
--Marc Cassuto--

Marc Cassuto
On 8/7/13, 2:44 PM

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
                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.


PS: please vote if you find it helpful.

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

on 2/20/14, 8:44 AM

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

on 2/20/14, 9:19 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/6/13, 11:50 AM
Seen: 4146 times
Last updated: 3/16/15, 8:10 AM