Enable Dark Mode!
how-to-add-a-button-inside-action-menu-in-odoo-16.jpg
By: Swapna

How To Add a Button Inside Action Menu in Odoo 16

Technical Odoo 16

Using the action menu button in Odoo, we could wish to take some action to modify the current record or set of records. This blog post addresses modifying or updating the current record or group of records as well as adding a button to the action menu. You can change an action for a single record or a group of records by using the action menu button. However, only the operations for the present records will be impacted by the buttons inside the record.

The button is displayed in the form view and tree view in Odoo action. We can put a button inside the form view if we just want to act on one record. If not, we may incorporate a button inside the tree view to handle multiple or selected records.

To add a button inside an action menu in Odoo 16, you need to follow the following steps:

We can consider an example of adding an “Update invoice date” button via the action menu 

Step 1. First, we can create a python function to update the invoice date.

class AccountMoveInherit(models.Model):
   _inherit = 'account.move'
   def action_update_invoice_date(self):
       self.write({'invoice_date': fields.Date.today()})

Step 2. Define a new action in the XML file:

<record model="ir.actions.server" id="action_update_invoice_date">
       <field name="name">Update Invoice Date</field>
       <field name="model_id" ref="account.model_account_move"/>
       <field name="binding_model_id" ref="account.model_account_move"/>
       <field name="state">code</field>
       <field name="code">
           action = records.action_update_invoice_date()
       </field>
</record>

So, under the actions menu, we can see a button/submenu named as “Update Invoice date”.

How To Add a Button Inside Action Menu in Odoo 16-cybrosys

Upon clicking “Update Invoice Date” we can see that the invoice date becomes updated.

How To Add a Button Inside Action Menu in Odoo 16-cybrosys

Currently, this is only available in the form view. If you want to add this under the tree view, please add the code below.

<field name="binding_model_id" ref="account.model_account_move"/>
<field name="binding_view_types">list,form</field>
‘binding_model_id’ defines which model is adding the action. ‘binding_view_types’ defines the view type for which action appears.

These are the steps for creating a button under the action menu.


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



1
Comments

LADEON Rudi

Hello, How to hide action Odoo like : Export, Archive, UnArchive or custom action for some users groups ?

09/10/2023

-

9:53PM



Leave a comment

 


whatsapp
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