Odoo 16 Studio Book - Adding a New Button

Let's add buttons to perform some specific actions using the Studio module. Creating a new button is quite different from creating other features with Studio because it involves some XML coding.

First, you have to enable the debug mode. Either you can enable it from the general settings or simply type

odoo-studio

In the URL after the web, as shown below:

odoo-studio

Now the debug mode is enabled. Now we have to create a server action to do some action while we click on the new button

  • Go to settings, and click on the Technical menu on top. It can be seen only with the developer mode.
  • Click on the Server Actions menu from the list of menus that come up when we click on Technical.
odoo-studio
  • Click on the ‘New’ button to create a new Server Action and fill in the required fields.
odoo-studio

Fields on the form:

  • Action Name - You can give a name for your action to identify the use.
  • Model - You can choose a model, which you want to add a button to
  • Action To Do - You can choose an action to do with your new button from a list of possible actions.
    1. Update the Record - If you want to update a record on the corresponding view, like set a field’s value, you can select this action. Then you have to specify the field.
    2. Create a new Record - If you want to create a new record on a button click, you can select this action. Then you have to specify the fields and corresponding values to create the record
    3. Execute Python Code - If you want to perform some calculations or complex operations on the button click, you can choose the Execute Python Code action, and then you have to write the Python code for that operation.
    4. Execute several actions - If you want to execute a set of child actions, you can choose this action, and then you have to specify the child server actions.
    5. Send Email - If you want to send an email on a button click, you can choose this action, and then you have to specify the email template.
    6. Add Followers - If you want to add followers to your selected record, you can choose this action, and then you have to add the followers in the Add Follower field.
    7. Create Next Activity - If you want to add an activity on the button click, you can choose this option, and then you have to configure the activity.
    8. Send SMS Text Message - You can send SMS on the button click by using this option. Then you have to specify the SMS template.
odoo-studio
  • Fill in all the necessary fields, then save the server action.
  • You can see the id of the server action from the URL as shown below:
odoo-studio
  • Copy the id of the server action.
  • Then you can open the view, where you want to add your button. Here I selected the sale order form view and opened the studio.
  • You can click on the View menu on the studio screen and then the XML tab, as shown below.
odoo-studio
  • You can see the XML code for the selected view on the left side. Inside the header tag, you can see the code for buttons that are already in that view.
odoo-studio
  • You can define the new button inside the header like the one below and add the id of the created server action as the name in it.
odoo-studio
  • Then you can see your button on the view, and while clicking it, the defined server action will be executed.
odoo-studio
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