Search code examples
pythonodooodoo-11

how to hide button create/edit in module employee to employee who belongs to group Employee/employee?


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>

enter image description here


Solution

  • You can hide button create/edit from XML. Like the following:

    <field name="your_field_name" options="{'no_create_edit':True}" />
    

    I hope this helps you. Thank you.