How to see subordinate’s leave and Time sheets with Record Rule?

 

Take employee_ids as One2many Field of hr_employee in res_users class.

Inverse field should exist in the classhr_employee.

Reporting person of that employee should able see his respective leaves and Time sheet submitted by that employee.

Have 2 fields in the classhr_employee that employee hr manager and reporting manager who have access to see his subordinate’s leaves and time sheet.

As

In res_users class fields are”

'employee_id': fields.one2many('hr.employee','user_id',string="Employee") ——-Should be invisible in view

In hr_employee class the following fields should exist:

'hr_id':fields.may2one('hr.employee','Hr Manager'),

'user_id': fields.many2one('res.users', 'User') ——-Should be invisible in view

 

and in hr_holidays

'employee_id':fields.many2one('hr.employee', 'Employee', required=True)

in hr_analytic_timesheet

employee_id': fields.many2one('hr.employee', 'Employee', required=True)

 

Record Rule that shows employee leaves and timesheet:
For Leaves:

<record id="res_users_rule_for_hr_holidays" model="ir.rule">

<field name="name">Rule of hr holidays</field>

<field name="model_id" ref="model_hr_holidays"/>

<field name="domain_force">['|',('employee_id','child_of',[user.employee_id.id]),('employee_id.hr_id.user_id.id','=',user.id)]</field>

<field name="groups" eval="[(4, ref('base.group_user')),(4, ref('base.group_hr_manager')),(4, ref('base.group_hr_user'))]"/> —involved group that you want to show

</record>

 

For Timesheet:

<record id="res_users_rule_timesheet" model="ir.rule">

<field name="name">Rule of hr timesheet</field>

<field name="model_id" ref="model_hr_analytic_timesheet"/>

<field name="domain_force">['|',('employee_id.user_id','=',user.id),('employee_id','child_of',[user.employee_id.id])]</field>

<field name="groups" eval="[(4, ref('base.group_user')),(4, ref('base.group_hr_user'))]"/>

</record> —involved group that you want to show

 

Following record rule for admin

<record id="res_users_rule_for_hr_holidays_admin" model="ir.rule">

<field name="name">Rule of hr holidays for admin</field>

<field name="model_id" ref="model_hr_holidays"/>

<field name="domain_force">[(1, '=', 1)]</field>

<field name="groups" eval="[(4, ref('hr_enh.group_hr_ceo'))]"/>

</record>

<record id="res_users_rule_timesheet_admin" model="ir.rule">

<field name="name">Rule of hr timesheet for admin</field>

<field name="model_id" ref="model_hr_analytic_timesheet"/>

<field name="domain_force">[(1, '=', 1)]</field>

<field name="groups" eval="[(4, ref('hr_enh.group_hr_ceo'))]"/>

</record>

For further information, please visit Nevpro Business Solutions.

Connect with us on Google+!