Enable Dark Mode!
how-to-configure-scheduled-actions-in-odoo-15.jpg
By: Aswathi PN

How to Configure Scheduled Actions in Odoo 15

Technical Odoo 15

Scheduled actions are automated actions or computerized actions that run automatically over a period of time. The main use of Scheduled Actions is for the automated running of a process which is one of the best features in Odoo. Scheduled actions are also known as crown jobs.

In this blog, we will understand the configurations and the operational aspects of the Scheduled Actions in the new Odoo 15 platform.

Creating methods and models:

from odoo import models, fields
class MailActivity(models.Model):
   _name = 'mail.activity'
   def action_done(self):
       print("function")

Create Scheduled Actions:

Using the following code we have created a scheduled action:

<data noupdate="1">
   <record id="ir_cron_scheduler_recurring_action" model="ir.cron">
       <field name="name">Recurring Todo Activity</field>
       <field name="model_id" ref="model_mail_activity"/>
       <field name="state">code</field>
       <field name="code">model.action_date()</field>
       <field name="user_id" ref="base.user_root"/>
       <field name="interval_number">1</field>
       <field name="interval_type">days</field>
       <field name="numbercall">-1</field>
   </record>
</data>

Lets now understand on how the above mentioned code is used to define the Scheduled Actions in the Odoo platform.

<data noupdate="1">

noupdate="1" will be initialized at the time of installation, this will not be updated after installation. Moreover, the automated actions are always defined inside a noupdate field.

<record id="ir_cron_scheduler_recurring_action" model="ir.cron">

The ID is an identifier that is unique for each record and that record will be stored in the  ir.cron table

<field name="name">Recurring Todo Activity</field>

Assign a name for the Scheduled action. That we can see in the UI and should give a meaning full name to the field.

<field name="model_id" ref="model_mail_activity"/>

This specifies that on which model is the automated action called in. 

<field name="state">code</field>
<field name="code">model.action_date()</field>

Here we need to specify the method name to be called.

<field name="user_id" ref="base.user_root"/>

In this the user ID is referring to a specific user, in most cases base.user_root is used.

<field name="interval_number">1</field>
<field name="interval_type">days</field>

name=”interval_number” specifies that the number of times scheduled action is to be called based on interval_type

interval _type is the interval unit

<field name="numbercall">-1</field>

It is an integer value, which specifies how many times the action is executed. We want the action to run forever just put it to -1

For example:

Question: In XML it has interval_type and interval_number. How to make it run at a specific time of day?

Answer:  

<field name="nextcall" eval="(DateTime.now()
timedelta(days=1)).strftime('%Y-%m-%d 12:00:00')" />
<field name="interval_type">days</field>

 at 12 o’clock everyday  it will be execute.

Configure Scheduled actions in UI:

For this first activate the developer mode then go to Settings > Technical > Automation > Scheduled Actions

how-to-configure-scheduled-actions-in-odoo-15

Click the Scheduled actions we can see the already created scheduled actions in a tree view. You can select any one of that see the form view

how-to-configure-scheduled-actions-in-odoo-15

Click the Create button we can create a new scheduled action

how-to-configure-scheduled-actions-in-odoo-15

Enter the scheduled action details like Action name, model, scheduled user, number of calls, priority, and many more. And also we can set the python method directly from this form view. This method will perform on the specified time that you set or otherwise we can run it manually by clicking the Run manual button.

In this way can create scheduled actions in Odoo 15.


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



0
Comments



Leave a comment



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