Please help me, I need to filter leave requests by department depending on the department of the user logged in.
I tried simple Print inside the method it is working but it doesn't open the action window
Please tell me what's wrong or if there's easier way to do it. Thank you so much in advance.
Here's my code:
Py:
@api.multi
def leave_filter_act(self):
hr_emp = self.env['hr.employee'].search([('user_id', '=', self.env.user.id)])
print hr_emp.department_id.id #this is working
return {
'name': _("Leave Approvals"),
'type': 'ir.actions.act_window',
'res_model': 'hr.holidays',
'view_mode': 'tree,form',
'view_type': 'form',
'views': [[False, 'tree'],[False, 'form'],],
'context': {'search_default_department_id': [hr_emp.department_id.id]},
'target': 'current',
}
XML:
<record id="action_server_leave_filter" model="ir.actions.server">
<field name="name">Leave Filter</field>
<field name="model_id" ref="model_hr_holidays"/>
<field name="code">env.get('hr.holidays').leave_filter_act()</field>
</record>
<menuitem
id="menu_open_department_leave_approve_offcr"
name="My Department"
parent="hr_holidays.menu_hr_holidays_approvals"
action="action_server_leave_filter"/>
Show records on TreeView that are related to Active User: https://goo.gl/hv4WAi