Odoo Help

Welcome!

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

1

Prevent HR Managers from approving their own leave requests

By
Odooveloper (by Rui Franco)
on 8/6/13, 11:50 AM 2,867 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.

:|

0

Marc Cassuto

--Marc Cassuto--
815
| 4 4 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
            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.

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

JK
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

JK
on 2/20/14, 9:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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