Enable Dark Mode!
how-to-add-a-button-inside-action-menu-in-odoo-17.jpg
By: Ayisha Sumayya K

How to Add a Button Inside Action Menu in Odoo 17

Technical Odoo 17

The Action Menu in Odoo 17 serves as a central hub for executing various actions on records. Adding a custom button to this menu can significantly enhance user workflows, providing quick and direct access to specific functionalities. This customization not only streamlines processes but also contributes to a more intuitive and efficient user experience.

Using the action menu button, you can modify an action for a single record or a collection of records. That is, the button appears in the Odoo action's form view and tree view. If we only want to make changes to one record, we can add a button inside the form view. If not, we might include a button to handle many or specific records inside the tree view.

Take a look at an example of using the action menu to add an "Update Order Date" button, which updates the sale order date to the current date.

Step 1: Create a module that includes the Python function to update the sale order date to the current date.

from odoo import fields, models
class SaleOrder(models.Model):
   _inherit = 'sale.order'
   def action_update_order_date(self):
      for rec in self.browse(self.env.context['active_ids']):
          rec.write({'date_order': fields.Date.today()})

Step 2: Add the following action to the XML file.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
   <record id="action_update_order_date" model="ir.actions.server">
       <field name="name">Update Order Date</field>
       <field name="model_id" ref="model_sale_order"/>
       <field name="binding_model_id" ref="sale.model_sale_order"/>
       <field name="binding_view_types">form</field>
       <field name="state">code</field>
       <field name="code">model.action_update_order_date()</field>
   </record>
</odoo>

The output of this code will display, as indicated in the figure, the “ Update Order Date ” action under the Action menu.

how-to-add-a-button-inside-action-menu-in-odoo-17-1-cybrosys

Before clicking the "Update Order Date" button, the value of the Order date field is 10/27/2023, as shown in the above figure. Upon clicking it, we can see that the Order date has been updated. 

how-to-add-a-button-inside-action-menu-in-odoo-17-2-cybrosys

We added this button only to the form view. If we want the button to appear in both the form and tree view, we can change the binding_view_types to form and tree, as indicated below.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
   <record id="action_update_order_date" model="ir.actions.server">
       <field name="name">Update Order Date</field>
       <field name="model_id" ref="model_sale_order"/>
       <field name="binding_model_id" ref="sale.model_sale_order"/>
       <field name="binding_view_types">form,list</field>
       <field name="state">code</field>
       <field name="code">model.action_update_order_date()</field>
   </record>
</odoo>

how-to-add-a-button-inside-action-menu-in-odoo-17-3-cybrosys

Customizing the Action Menu in Odoo 17 is a simple yet effective way to tailor the platform to your specific needs. By adding a custom button, you can improve user productivity and simplify access to essential functionalities.

To read more about adding a button inside the action menu in Odoo 16, refer to our blog How To Add a Button Inside Action Menu in Odoo 16


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message