Chapter 19 - Odoo 15 Development Book

Python Code Server Actions

This Server action enables users to execute python code and install code without having to create special add-ons modules.

Let's see how we can do this.

Enable the developer mode Then, Go to menu Settings -> Technical -> Automation -> Automated Actions. Click the ‘Create’ button.

If you want to set conditions for your fields when we create the record, you can easily specify this using the ‘Execute Python Code’ server action.

odoo-development-book

Model: res partner

Action To Do: Execute Python Code

Apply on: Specify condition before executing the action

Python code: If not record.parent_id: raise UserError('Add Email')

odoo-development-book

Automated Actions on time conditions

You can use automated actions to automatically trigger the actions based on time conditions. You can use them to automatically perform some operations on datasets that meet specific criteria and time constraints.

Let's see how we can do this.

Enable the developer mode

Then, Go to menu Settings -> Technical -> Automation -> Automated Actions. Click the ‘Create’ button to create a new one.

odoo-development-book

Model: Select the model in which the action applies.

Action to do: Select the Server action type.

Trigger: Select the trigger type.

Apply on: Specify Conditions before executing the action.

Email Template: Select the email template to send to the partners.

Trigger Date: Select Deadline, If we send the mail based on the project deadline field.

Delay after trigger date: If we set a negative value, the event will be triggered before the trigger date.

Automated Actions on event conditions

This type of automated action is mainly used to trigger an action when a specific event is generated. For example, if the logged-in user has access rights to the project leader or project manager, then only the project state can be updated.

Let's see how we can do this.

Enable the developer mode.

Then, Go to menu Settings -> Technical -> Automation -> Automated Actions. Click the ‘Create’ button.

odoo-development-book

Model: Task

Action To Do: Execute Python Code

Python Code: if user != record.project_id.user_id: raise ValueError("only the Project Manager or Project Administrator can change the state.")

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