in odoo 17 i want to remove the new button in the tree view and replace it with a custom…
- User
in odoo 17 i want to remove the new button in the tree view and replace it with a custom button
- Assistant
in odoo 17 i want to remove the new button in the tree view and replace it with a custom button
To remove the "New" button in the tree view and replace it with a custom button in Odoo 17, you will need to customize the XML view definition of the tree view. Here's a step-by-step guide to achieve this:
Inherit the View: First, you need to inherit the tree view where you want to make the modification. This is done by creating an XML file in your custom module.
Locate the Tree View: Identify which tree view you want to customize. You might need to check the XML ID of the original view. If you don't know it, you can find it in the original module's view files or use Developer mode in Odoo to inspect the view.
Create a Custom Module: If you haven't already, create a new custom module where you will define your customizations.
Define the XML: Create or update an XML file in your custom module with the following code. This removes the "New" button from the tree view and adds your custom button.
<odoo>
<data>
<!-- Inherit the target tree view -->
<record id="your_custom_tree_view_id" model="ir.ui.view">
<field name="name">Custom Tree View</field>
<field name="model">model.name</field> <!-- Replace with the actual model name -->
<field name="inherit_id" ref="original_tree_view_id"/> <!-- Replace with the actual view ID -->
<field name="arch" type="xml">
<!-- Remove the 'Create' button -->
<xpath expr="//tree" position="attributes">
<attribute name="create">false</attribute>
</xpath>
<!-- Add a custom button -->
<xpath expr="//tree" position="before">
<header>
<button name="your_custom_method"
string="Custom Button"
type="object"
class="oe_highlight"/>
</header>
</xpath>
</field>
</record>
</data>
</odoo>
Define the Custom Method: In your model's Python file, define the method that will be triggered by your custom button.
from odoo import models, api
class YourModel(models.Model):
_inherit = 'model.name' # Replace with the actual model name
@api.multi
def your_custom_method(self):
# Your custom logic here
return True
Update your Module: After making changes to your module, you need to update your module in Odoo. You can do this by going to the Apps menu in Developer mode, finding your module, and clicking the Update button.
Test Your Changes: Finally, navigate to the tree view you modified and ensure the "New" button is removed and your custom button is present and functioning as expected.
Remember to adjust model.name, original_tree_view_id, and your_custom_method with appropriate values based on your specific use case.