Hello,
Is there a mechanism how to run a code on Odoo startup, but when all the models are loaded and DB is ready?
The aim is to auto run some background tasks and services when the Odoo starts/restarts (just like bots etc.).
Thank you!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
Is there a mechanism how to run a code on Odoo startup, but when all the models are loaded and DB is ready?
The aim is to auto run some background tasks and services when the Odoo starts/restarts (just like bots etc.).
Thank you!
Hi,
Yes, there is a way to run code after Odoo has fully loaded, including all models and a ready database. If you want to kick off background tasks or services (like bots, listeners, etc.) right after startup, here's are steps:
Use post_init_hook or pre_init_hook (for one-time setup tasks)
These hooks can be defined in your __manifest__.py, but they're mostly intended for module installation or upgrade—not for every startup.
Easiest workaround: Use a scheduled action (cron)
Create a scheduled action that runs every minute (or just once, if you set number_of_calls = 1). It’s reliable and DB-aware.
Example:
xml
<record id="ir_cron_startup_task" model="ir.cron">
<field name="name">Startup Task</field>
<field name="model_id" ref="your_module.model_your_model"/>
<field name="state">code</field>
<field name="code">model.your_startup_method()</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="active">True</field>
</record>
If you only want it to run once, set numbercall to 1.
Hope it helps
Hello
I have the same question. The only idea I had so far is to launch a cron with a 1 minute interval.
BR
Nico
Please tell in more details
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
3
aug. 25
|
2850 | ||
|
1
mei 25
|
2782 | ||
|
1
apr. 25
|
3744 | ||
|
1
apr. 25
|
4613 | ||
|
1
apr. 25
|
2050 |