Skip to Content
Menu
This question has been flagged
1 Reply
5365 Views

i develop a custom module to restrict the right to create a new employee or to modify an existing one to the employees who belongs to group "Employee/Employee" but i notice even though my employee has the right "Employee/Manager" he became not able to create or edit employees. How can i fix that problem ? Any idea for help please ? here is my code :

hr_employee_view.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_hr_employee_form_remove_edit" model="ir.ui.view">
    <field name="name">view.hr.employee.form.remove.edit</field>
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="hr.view_employee_form"/>
    <field name="groups_id" eval="[(4,ref('base.group_user'))]"/>
    <field name="arch" type="xml">
        <xpath expr="//form" position="attributes">
            <attribute name="edit">false</attribute>
            <attribute name="create">false</attribute>

        </xpath>
    </field>
</record>

<record id="view_hr_employee_tree_remove_edit_create" model="ir.ui.view">
    <field name="name">view.hr.employee.tree.remove.edit.create</field>
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="hr.view_employee_tree"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_user')])]"/>
    <field name="arch" type="xml">
        <xpath expr="//tree" position="attributes">
            <attribute name="edit">false</attribute>
            <attribute name="create">false</attribute>
        </xpath>
    </field>
</record>

<record id="view_hr_employee_kanban_remove_edit_create" model="ir.ui.view">
    <field name="name">view.hr.employee.kanban.remove.edit.create</field>
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_user')])]"/>
    <field name="arch" type="xml">
        <xpath expr="//kanban" position="attributes">
            <attribute name="edit">false</attribute>
            <attribute name="create">false</attribute>
        </xpath>
    </field>
</record>

</odoo>



Avatar
Discard
Best Answer

When you add attributes create='false' edit='false' in your views, on these views the button create and edit will be hidden for all groups of users.

Please use the model access right in your security file ir.model.access.csv.

This is an example:

access_hr_employee_user,hr.employee user,model_hr_employee,hr.group_hr_user,1,0,0,0 
access_hr_employee_manager,hr.employee hr_manager,model_hr_employee,hr.group_hr_manager,1,1,1,1

The first line is employee access right and the second is for manger

Avatar
Discard
Related Posts Replies Views Activity
2
Feb 24
13188
1
Dec 22
3859
2
Dec 22
12724
2
Jun 22
4688
2
Jun 22
3504