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

Domain based on group

By
fho
on 5/11/16, 11:09 AM 548 views

Hi,

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"/>

</tree>

</field>

</record>

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

<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')])]"/>

</record>

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

2 follower(s)

Stats

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