Introduction
Scheduled Actions (aka cron jobs) in Odoo are the unsung heroes behind the scenes. Whether it’s auto-reminders, data cleanup, syncing with external services, or sending weekly reports, these timed scripts make magic happen.
If you’re a developer or tech admin wanting to harness automation powerfully, this is your go-to guide.
What Are Scheduled Actions in Odoo?
Scheduled actions are background jobs defined to execute Python code at specific intervals (daily, hourly, etc.)
They live in ir.cron, Odoo’s built-in job scheduler.
To make the most of scheduled actions, it’s essential to understand how Odoo’s ORM works—check out our Odoo ORM Guide to explore the framework’s core.
Why Use Scheduled Actions?
- Automate routine tasks
- Trigger updates or batch processes
- Send alerts or reminders
- Sync with external APIs periodically
Creating a Basic Scheduled Action
You can define it in your custom module using XML:
<record id=”model_run_cron” model=”ir.cron”>
<field name=”name”>Run My Custom Cron</field>
<field name=”model_id” ref=”model_my.model_name”/>
<field name=”state”>code</field>
<field name=”code”>model.my_method()</field>
<field name=”interval_number”>1</field>
<field name=”interval_type”>days</field>
<field name=”numbercall”>-1</field>
</record>
Backend UI: Where to Manage Scheduled Actions
Navigate to: Settings → Technical → Automation → Scheduled Actions
There, you can:
- Enable/disable jobs
- Change frequency
- Run manually for testing
Building Python Methods for Cron Jobs
Here’s how a method looks:
@api.model
def my_method(self):
records = self.env[‘sale.order’].search([(‘state’, ‘=’, ‘draft’)])
for rec in records:
rec.action_confirm()
Using numbercall and interval Wisely
- numbercall = -1: Infinite executions
- interval_type: can be minutes, hours, days, weeks, months
- nextcall: The next datetime the job will run
Best Practices for Writing Scheduled Actions
- Always catch exceptions with try-except
- Log activity using logging
- Avoid long-running tasks—use job queues if needed
- Never hardcode values—use config parameters
Debugging Scheduled Actions
- Run manually from UI to test
- Add print() or logger.info() inside methods
- Monitor logs using tail -f odoo.log
Use Case Examples
1. Daily Reminder Emails
Send reminder to users whose subscriptions are about to expire.
2. Auto-Confirm Orders
Automatically confirm quotations after 48 hours.
3. Data Sync with External Services
Integrate with APIs on schedule to update stock or pull data.
When to Use Job Queues Instead
If your task:
- Takes more than a few seconds
- Involves external API delays
- Requires retry logic
Then use queue_job module to handle asynchronously.
Security and Performance Considerations
- Always check access rights using sudo() sparingly
- Avoid intensive DB queries inside cron
- Monitor job failures regularly
Conclusion
With Scheduled Actions, Odoo turns into an autonomous digital assistant. Once set up, it runs quietly and efficiently—like your ERP’s heartbeat. When done right, it can save hours of manual work and reduce operational bottlenecks.
Automate smart, automate safe.
Ready to streamline your workflows with smart automation? Book a customization session today and let us tailor Scheduled Actions to your business needs.
Frequently Asked Questions
1. Can I stop a running cron job?
Yes—disable from UI or remove the cron record.
2. How do I prevent overlap between two jobs?
Use locking mechanism in your method logic.
3. Is there a limit to how often I can run a job?
No, but high-frequency jobs may impact performance.
4. Can scheduled actions send emails?
Absolutely—use the mail.mail model to send messages.
5. What happens if a cron job fails?
It logs the traceback in ir.cron and tries again on the next interval.