Automated actions can be used to automatically trigger actions based on a time condition. We can use them to automatically perform some operation on records that meet certain criteria and reach time condition.Schedulers are automated actions that run automatically over a time period and can do a lot of things. They execute actions without manual interaction and makes background job very easy: For this simply insert a record to the ir.cron table and Odoo will execute it as defined.
1. Creating the model and fields
The first step is to create a model (if you don’t have one yet) and to create some fields on this model:
_name = 'model.name'
fields_name = fields.Char(string=" ")
"Your code here"
2.Creating the views
Now that you have the database part ready it is time to create your view
3. Creating the automated action
<?xml version="1.0" ?>
<record id="backup_scheduler" model="ir.cron">
<field name="name">Backup scheduler</field>
An important thing to note with automated actions is that they should always be defined within a noupdate field since this shouldn’t be updated when you update your module.
The first thing you notice is the data noupdate="1", this is telling Odoo that all code within this tag shouldn’t be updated when you update your module.
<record id="unique_name" model="ir.cron">
The id is a unique identifier for Odoo to know what record is linked to which id. The model called (“ir.cron”) is the model specifically made by Odoo for all automated actions. This model contains all automated actions and should always be specified.
<field name="name">Name </field>
The next line is the name.
<field name="active" eval="True" />
Boolean value indicating whether the cron job is active or not.
<field name="user_id" ref="base.user_root"/>
This user id is referring to a specific user, in most cases this will be base.user_root.
Number of times the scheduler is to be called based on the “interval_type”
It should be one value for the list: minutes, hours, days, weeks, months.
An integer value specifying how many times the job is executed. A negative value means no limit.
A boolean value indicating whether missed occurrences should be executed when the server restarts
<field name="nextcall" >2016-12-31 23:59:59</field> <!-- notice the date/time format -->
Next planned execution date for this job.
<field name="model" eval="'model.name '" />
The field model specifies on which model the automated action should be called.
<field name="function" eval="'method_name '" />
Name of the method to be called when this job is processed.
<field name="args" eval="" />
The arguments to be passed to the method.
<field name="priority" eval="5" />
The priority of the job, as an integer: 0 means higher priority, 10 means lower priority.