Enable Dark Mode!
how-to-configure-schedule-actions-in-the-odoo-16.jpg
By: Sruthi C Nair

How to Configure Schedule Actions in the Odoo 16

Technical Odoo 16

Automated or computerized actions that are scheduled to run automatically over time are called scheduled actions. One of the best features of Odoo is the automated running of processes, which is the primary purpose of Scheduled Actions. The term "crown jobs" also refers to scheduled actions. 

In this blog, we will learn about the settings and functionality of the new Odoo 16 platform's Scheduled Actions.
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_done()</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>
Let's see how the aforementioned code is applied to the Odoo platform to define the Scheduled Actions.
<data noupdate="1">

Let's now comprehend how the aforementioned code is applied to the Odoo platform's Scheduled Actions.

<data noupdate="1">
After installation, noupdate="1" won't be updated; instead, it will be initialized. The automated actions are always specified in a no update field as well.
<record id="ir_cron_scheduler_recurring_action" model="ir.cron">

Each record's ID serves as a unique identifier, and that record will be kept in it. 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 meaningful name to the field.

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

This specifies 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 refers 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 that indicates the frequency of execution of the action.

Put it to -1 if we want the action to continue indefinitely. For instance, There are interval types and interval numbers in XML. How can I set it to operate at a certain 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 every day it will be executed.

Configure Scheduled actions in UI:

After enabling developer mode, navigate to Settings > Technical > Automation > Scheduled Actions.

how-to-configure-schedule-actions-in-the-odoo-16-1-cybrosys

The Scheduled actions link. The already established scheduled actions are displayed in a tree format. You can choose any of those to view the form view.

how-to-configure-schedule-actions-in-the-odoo-16-2-cybrosys

By selecting the Create button, a new planned action can be created.

how-to-configure-schedule-actions-in-the-odoo-16-3-cybrosys

Input the scheduled action model, scheduled user, number of calls, priority, and other details. Additionally, we can directly set the Python method from this form view. If you choose a specific time for this method to run, it will do so; if not, we can manually run it by selecting the Run manual button. In this manner, Odoo 16 users can establish scheduled actions.


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