Creating & Configuring Server Actions in Odoo 17

Server Actions in Odoo act as a dynamic tool for automating processes without requiring extensive custom development. These actions allow users to outline a series of operations or tasks that the system automatically executes under specific conditions. From creating records and updating fields to initiating complex business logic, Server Actions empower users to automate routine tasks and intelligently respond to different scenarios within the ERP environment.

To access all available server actions in the Odoo system, activate debug mode, then navigate to Settings -> Technical -> Server Actions.


Here is the roster of current server actions in Odoo 17.


A server action can execute the following categories of actions.

1. Run Python code

2. Generate a new record

3. Modify existing record

4. Dispatch an email

5. Dispatch an SMS message

6. Include followers

7. Generate the next activity

8. Perform multiple actions

Establish a fresh server action

In this blog post, generate a server action to transfer data from the 'phone' field to the 'mobile' field within the 'res.partners' model.

The server action should be specified within the "ir_action_data.xml" file located in the "data" directory of your module.

<record id="copy_phone_to_mobile" model="ir.actions.server">
   <field name="name">Copy phone to mobile</field>
   <field name="model_id" ref="base.model_res_partner"/>
   <field name="binding_model_id" ref="base.model_res_partner"/>
   <field name="binding_view_types">list</field>
   <field name="state">code</field>
   <field name="code">
       action = records.action_copy_phone_to_mobile()
   </field>
</record>

Within this code segment

- name: designates the title of the server action, visible in the server actions menu.

- model_id: denotes the model connected to the server action, formatted as <module>.model_<model_name>

- binding_model_id: It indicates that the action is bound to the referencing model.

- binding_view_types: determines the views in which the action should be accessible for the associated model.

- state: Indicates the type of server action as discussed previously; in our scenario, we select it as "code" to execute a Python script.

- code: defines the Python script to be executed.

Upon adding the XML code, ensure to integrate the function "action_copy_phone_to_mobile()" into the res.partner model, as specified in the server action.

def action_copy_phone_to_mobile(self):
   for record in self:
       if record.phone and not record.mobile:           
record.write({'mobile': record.phone})

Now, we can utilize this server action on the contacts list view.

Choose contacts lacking mobile fields yet possessing phone fields, then beneath the "Actions" menu, you'll find a freshly created server action button titled "Copy phone to mobile."

The outcome will be.

The recently created server action is also accessible in Server Actions under the Technical menu from settings.

To sum up, Odoo Server Actions enable users to automate various processes, improving efficiency and minimizing manual intervention, thus streamlining operations within the ERP environment.

Managing Loyalty Programs in Odoo 17 POS