Odoo 17 Customization: Remove Delete Icon from Tree View
Odoo is a powerful and flexible ERP system that allows extensive customization to fit business needs. Sometimes, you may want to restrict users from deleting records directly from the tree view to maintain data integrity. In this tutorial, I’ll guide you through the steps to remove the delete icon from the tree view in Odoo 17.
Prerequisites
Before you start, ensure you have:
- Odoo 17 installed and running
- Basic understanding of Odoo models and views
- Access to the Odoo server with the necessary permissions to modify XML files
Step 1: Identify the Tree View
The first step is to identify the tree view from which you want to remove the delete icon. You can find the tree view definition in the corresponding XML file of the module.
For example, if you are working with the sale.order
model, the tree view might be defined in views/sale_order_views.xml
.
Step 2: Modify the Tree View XML
Once you’ve identified the tree view, locate the XML file and open it in your favorite editor.
Find the <tree>
tag for the relevant model and add the create
and delete
attributes to it. This attributes delete="false"
will remove the delete icon.
Here’s an example:
<record id="view_order_tree" model="ir.ui.view">
<field name="name">sale.order.tree</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<tree create="true" delete="false">
<!-- Your fields here -->
<field name="name"/>
<field name="partner_id"/>
<field name="date_order"/>
<!-- Other fields -->
</tree>
</field>
</record>
In this code snippet:
create="true"
allows the creation of new records.delete="false"
hides the delete icon.
Step 3: Update the Module
After making the changes, you’ll need to update the module for the changes to take effect.
- Go to the Odoo interface.
- Navigate to Apps and click Update Apps List.
- Search for your module and click on Upgrade.
Alternatively, you can update the module from the command line:
# In pycharm code editor
-c /custom/odoo.conf -u your_module_name -d your_database_name --dev=xml
# Form cmd/ Terminal
./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -u your_module_name -d your_database_name --dev=xml
This command will update your module and apply the changes.
Step 4: Verify the Changes
Once the module is updated, go to the tree view in Odoo interface. The delete icon no longer be visible.
Conclusion
Removing the delete icon from a tree view in Odoo 17 is a straightforward process that enhances data security by preventing accidental deletions. By modifying the XML definition of the tree view, you can control user actions and ensure data integrity.