
Learn how to remove Create, Edit, Delete, and Duplicate options in Odoo form views. Follow this step-by-step guide to customize form actions, enhance data security, and streamline user permissions
Odoo provides a highly flexible platform for businesses to manage various operations, and one of its powerful features is the form view, where users can create, edit, delete, or duplicate records. However, in certain scenarios, you might want to limit these options to maintain data integrity, streamline operations, or prevent unauthorized actions.
This blog will guide you through the process of removing the Create, Edit, Delete, and Duplicate options in Odoo form views. These options can be disabled for specific models or views, based on your requirements.
There are several reasons why you might want to restrict these options in Odoo:
Below is a detailed step-by-step guide on how to remove these options in Odoo form views.
The create and edit options can be disabled directly in the form view by setting the create and edit attributes to false.
Example XML Code:
<record id="view_product_form" model="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="arch" type="xml">
<form string="Product" create="false" edit="false">
<sheet>
<group>
<field name="name"/>
<field name="default_code"/>
</group>
</sheet>
</form>
</field>
</record>
In the code above:
To remove the Delete option from the form view, you need to modify the access rights of the corresponding user groups or models. By setting delete to false, users will no longer be able to delete records from the form.
Example XML Code:
<record id="view_product_form" model="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="arch" type="xml">
<form string="Product" delete="false">
<sheet>
<group>
<field name="name"/>
<field name="default_code"/>
</group>
</sheet>
</form>
</field>
</record>
The delete="false" attribute ensures that the "Delete" button is hidden in the form view.
Odoo's Duplicate option is part of the action dropdown that appears in the top right corner of form views. To remove the duplicate option, you will need to override the action linked to that button.
Example Python Code:
from odoo import models, fields, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(ProductTemplate, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
for action in list(res.get('toolbar', {}).get('action', [])):
if action.get('name') == 'Duplicate':
res['toolbar']['action'].remove(action)
return res
In this code:
You can combine all of the above options to create a form view that restricts creating, editing, deleting, and duplicating records.
Example XML Code:
<record id="view_product_form" model="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="arch" type="xml">
<form string="Product" create="false" edit="false" delete="false">
<sheet>
<group>
<field name="name"/>
<field name="default_code"/>
</group>
</sheet>
</form>
</field>
</record>
By setting the attributes for create, edit, and delete to false, you effectively disable these actions from the form view.
If you only want to restrict these options for specific users or groups, you can do so by creating access control lists (ACLs) and record rules that limit the permissions for certain groups.
Example Python Code:
from odoo import models, fields, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
def _restrict_create_edit_delete(self):
if self.env.user.has_group('sales_team.group_sale_salesman'):
self.write({'create': False, 'edit': False, 'delete': False})
In this code:
Disabling the Create, Edit, Delete, and Duplicate options in Odoo form views is a straightforward process that can help you control user permissions and protect data integrity. By following the steps outlined in this guide, you can customize your Odoo form views to meet your business needs while maintaining control over how records are managed.
Your email address will not be published. Required fields are marked *