Odoo Help


Domain based on group

on 5/11/16, 11:09 AM 1,413 views


I want to change the default behavior of the human resources module.

I have two groups, hr_manager and hr_user.

I want Leaves Summary to display :

- for hr_managers => all the leaves summary

- for hr_users => only their leaves

I thought I would use a domain to achieve that :

# Step 1 : Retrieving groups_id

<field name="groups_id" eval="[(6,0,[ref('base.group_hr_manager')])]"/>

# Step 2 : Got uid in one hand, groups_id in the other - How can i make the connection ?

# What's in groups_id ? Only the groups_id (that seems the case) or "full" relation ?

# The idea was : if uid is in hr_manager group => display everything, else display only records filtered by uid

<field name="domain">[('type','=','remove'), ???, ('user_id','=',uid)]</field>

Any 'clean' ideas (with code sample, please) ?

Full code (tree view, action and menu item) :

<record id="mycompany_hr_view_grant_leaves_tree" model="ir.ui.view">

<field name="name">mycompany.hr.view.grant.leaves.tree</field>

<field name="model">hr.holidays</field>

<field name="type">tree</field>

<field name="priority">1</field>

<field name="mode">primary</field>

<field name="arch" type="xml">

<tree string="Grant Leaves" default_order="date_from desc"

colors="red:state == 'refuse';blue:state == 'draft';black:state in ('confirm','validate','validate1')">

<field name="employee_id"/>

<field name="holiday_type"/>

<field name="category_id"/>

<field name="department_id"/>

<field name="type"/>

<field name="name"/>

<field name="number_of_days" string="Allocated Days" sum="Remaining Days"/>

<field name="holiday_status_id"/>

<field name="manager_id"/>

<field name="manager_id2"/>

<field name="user_id" invisible="1"/>

<field name="state"/>

<field name="year"/>




<record id="mycompany_hr_action_leaves_summary" model="ir.actions.act_window">

<field name="name">Leaves Summary</field>

<field name="res_model">hr.holidays</field>

<field name="view_mode">calendar,tree,form</field>

<field name="search_view_id" ref="mycompany_hr_leaves_search"/>

<field name="groups_id" eval="[(6,0,[ref('base.group_hr_manager')])]"/>

<field name="domain">[('type','=','remove'),(uid,'in',groups_id),('user_id','=',uid)]</field>


<record id="hr_holidays.menu_open_company_allocation" model="ir.ui.menu">

<field name="name">Leaves Summary</field>

<field name="action" ref="mycompany_hr_action_leaves_summary"/>

<field name="groups_id" eval="[(6,0,[ref('base.group_hr_user')])]"/>


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

2 follower(s)


Asked: 5/11/16, 11:09 AM
Seen: 1413 times
Last updated: 5/18/16, 11:23 PM