Enable Dark Mode!
how-to-create-configure-server-actions-in-the-odoo-15.jpg
By: Sreerag E

How to Create & Configure Server Actions in the Odoo 15

Technical Odoo 15

We can meet specific requirements in Odoo using the “Server Actions “ feature. This blog discusses how we can use the Server actions and their various parameters. 

When a server action is created, it will be added to the “Action” contextual menu. It can be configured from Settings > Technical > Server Actions. Ensure the developer mode is enabled for accessing the “Technical” menu.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

The following are the available actions to do while creating a server action.

1. Execute Python Code

2. Create a new Record

3. Update the Record

4. Execute several actions

5. Send an Email

6. Add Followers

7. Create the Next Activity

8. Send an SMS Text Message

The server actions come in handy when we have to execute some small tweaks directly to the Odoo system. 

For creating a server action inside our custom module, we have to make a data record in the “ir.actions.server” model. Let’s create data.xml inside or data directory. This server action sets a specific user as a salesperson for a contact.

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
        <record id="action_set_salesperson" model="ir.actions.server">
            <field name="name">Set Salesperson</field>
            <field name="model_id" ref="base.model_res_partner"/>
            <field name="state">code</field>
        </record>
    </data>
</odoo>

Here,

model_id - is the model linked to the action

name - Name of the server action

state - It is the type of server action.

Now let’s look at the various types of server actions and their working.

1. Execute Python Code

<field name="state">code</field>

Using this type of server action, we can execute a python code. The available variables that we can use in this code are the following,

env: Odoo Environment on which the action is triggered

model: Odoo Model of the record on which the action is triggered; is a void recordset

record: record on which the action is triggered; may be void

records: recordset of all records on which the action is triggered in multi-mode; may be void time, datetime, dateutil, timezone: useful Python libraries

float_compare: Odoo function to compare floats based on specific precisions

log: log(message, level='info'): logging function to record debug information in ir.logging table

UserError: Warning Exception to use with raise

Command: x2Many commands namespace

For example, here the server action just copies the contacts phone number to the mobile field.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

After creating the server action, click the “Create Contextual Action” button on the header, and refresh the resulting model view. Then, the newly created server action will be available under the “Actions” menu

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

2. Create a new Record

<field name="state">object_create</field>

Here, the server action will create a new record in the target model.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

3. Update the record

<field name="state">object_write</field>

This type of server action can be used to update the values of a record. Here this server action sets “Marc Demo” as the salesperson for the contact.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

4. Execute Several Actions

<field name="state">multi</field>

We can use this type if we want to trigger several other server actions. Once we select the required model, it will list the available server actions for that model in the bottom table that we can select.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

Select the child actions by clicking on the“Add a line” in the Actions table.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

5. Send an Email

<field name="state">email</field>

This action is used to send emails to the specified group of partners.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

Create a contextual action, and it will be displayed in the Actions menu. One main advantage is we can execute the action for multiple records at the same time. In this example, we can send the mail to multiple contacts using this server action.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

6. Add Followers

<field name="state">followers</field>

We can use this action to add followers to a record. Select the required model, and add the contacts in the “Add followers” field.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

Execute the action for arecord and the contacts mentioned in the server action will be added asfollowers for the corresponding record.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

7. Create the Next Activity

<field name="state">next_activity</field>

For a record, we can set a next activity such as Email, Call, meeting, etc. using this server action. We can mention the number of due days as well as the responsible user to handle the activity.

In this example, a server action is created to schedule a meeting in 3 days to discuss the contract with the customer.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

8. Send an SMS Text Message

<field name="state">sms</field>

This action is similar to “Send Email”. We can trigger this action to send an SMS to partners using the template we mentioned in action.

how-to-create-configure-server-actions-in-the-odoo-15-cybrosys

So these are the available type of server actions that we can create in Odoo 15. These come in very handy in such cases where we need to apply some updates for bulk data.


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



0
Comments



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