Development Book V18: Creating Server Actions

Server actions in Odoo 18 allow you to automate operations directly on database models. These actions can be triggered manually by users, automatically via automation rules, or programmatically through code. They offer flexibility for operations like updating fields, executing Python code, sending emails, and more—all without writing full modules.

Accessing Server Actions

To create a server action:

  • Enable Developer Mode.
  • Go to Settings > Technical > Actions > Server Actions.

You’ll see a list of existing server actions. From here, you can create a new one.

odoo-development

Types of Server Actions

When creating a server action, you're asked to choose a model and an action type. Below are the supported types in Odoo 18:

  1. 1. Update Record
  2. 2. Create Record
  3. 3. Execute Python Code
  4. 4. Execute Existing Actions
  5. 5. Send Email
  6. 6. Send SMS
  7. 7. Add Followers
  8. 8. Remove Followers
  9. 9. Create Activity
  10. 10. Send Webhook Notification

Each action type is designed for a specific use case.

odoo-development

Example: Creating a Server Action via XML

You can also define server actions through XML, useful for modules or customizations:

<record id="action_set_salesperson" model="ir.actions.server">
  <field name="name">Set Sales Person</field>
  <field name="model_id" ref="base.model_res_partner"/>
  <field name="state">code</field>
</record>
  1. model_id defines the model this action operates on.
  2. state defines the type of action (e.g., code, object_write, etc.).

Action Type Breakdown

1. Update Record

Used to update fields on existing records. For example, assigning a salesperson to contacts:

  • Set the action type to Update Record.
  • Choose a model (like res.partner).
  • In the "Action Details" section, define the field and value to update.

Click "Create Contextual Action" to make the action available from list or form views.

odoo-development

2. Create Record

Used to generate new records in a specified model. You define which model to create and populate any necessary fields.

odoo-development

3. Execute Code

Lets you write Python code that will run on the records selected.

odoo-development

Example XML:

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

4. Execute Existing Actions

Allows you to chain multiple existing server actions together. Ideal for building complex flows by combining smaller actions.

odoo-development

XML:

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

5. Send Email

Enables you to send emails from the selected record context. You can choose whether to send as Email, Message, or Note.

odoo-development

XML:

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

6. Send SMS

Works similarly to the email action but sends SMS notifications. Select whether it should be just SMS, with a note, or only a note.

odoo-development

XML:

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

7. Add Followers

Adds specified partners as followers to the record.

  • Select the target model.
  • Choose partners to add.
odoo-development

XML:

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

8. Remove Followers

Removes partners from the follower list of a record.

odoo-development

XML:

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

9. Create Activity

Schedules an activity (like a call, meeting, or email follow-up) for the target record.

odoo-development

XML:

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

10. Send Webhook Notification

Sends a webhook (HTTP POST) to a specified endpoint. This is useful for integrating with external systems.

  • Define the URL endpoint.
  • Choose which fields to send in the payload.
odoo-development

Odoo 18 server actions are a powerful no-code/low-code automation tool. Whether you're looking to schedule reminders, trigger notifications, update records, or integrate with external platforms, server actions give you the flexibility to define business logic within the user interface or extend it through XML and Python.

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