To create a scheduled action in Odoo, navigate to Settings > Scheduled Actions. Here, you'll find a list of existing actions. Click on any action to view its details.
As depicted in the screenshot, each action corresponds to a specific model and method within that model. You can customize the execution time, frequency, and other settings for each action.
To create your own action, follow these steps:
In your custom module, create a new file named
cron.xml
within thedata
folder.-
Add the following XML code to the
cron.xml
file:<record id="custom_cron_job" model="ir.cron">
<field name="name">Custom Cron Job</field>
<field name="model_id" ref="custom_module.model_remote_warehouse"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="active" eval="True"/>
<field name="code">model_remote_warehouse.update_remote_products_report()</field>
</record>
In this XML code:
-
<field name="model_id" ref="custom_module.model_remote_warehouse"/>
specifies the full model name and method to be executed, such as'custom_module'.name_of_the_method
. In our example, the methodupdate_remote_products_report()
is defined in theremote_products.py
model file.
This setup ensures that the specified method will be executed each time the scheduled action runs, allowing you to perform custom tasks as needed.
important
dont forget to add the name of the action method as in the screenshot