Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
6874 Ansichten

I tried to create a cron job in Odoo 15 and it is not working at all even though the terminal returns that the cron job was executed. 


I used this in my "automation.xml" file: 

noupdate="0">
id="ir_cron_scheduler_sync_status_action" model="ir.cron">
name="name">Auto Sync Payment Status
name="model_id" ref="model_model_name"/>
name="state">code
name="code">model.test_cron()
name="user_id" ref="base.user_root"/>
name="interval_number">1
name="interval_type">minutes
name="numbercall">-1

And my function is as simple as this:

@api.model
def test_cron(self):
print("test cron")


But when I run this scheduled action manually or I just let the server executes it, nothing is printed in the terminal. What might be the issue here? Please help!


Avatar
Verwerfen
Beste Antwort

Here are some possible solutions to troubleshoot the issue:

  1. Check Cron Configuration: Ensure that your cron job is properly configured in the automation.xml file. Double-check the correctness of the element structure and attributes, such as name, model_id, state, code, user_id, interval_number, and interval_type.log files are located in the Odoo installation directory. Look for any relevant entries that may provide insights into the issue.

  2. Enable Developer Mode: Enable the developer mode in Odoo to see detailed error messages. You can enable it by adding ?debug at the end of the URL or by activating the developer mode through the user interface (by going to "Settings" -> "Activate the Developer Mode").

  3. Restart Odoo Service: Restart the Odoo service to ensure that any changes made to the cron job or module are properly applied. Sometimes, changes may not take effect until the service is restarted.

  4. Verify Access Rights: Ensure that the user specified in the user_id attribute of the cron job has the necessary access rights to execute the job. The user should have appropriate permissions on the model and its associated methods.

  5. Check Server Timezone: Make sure the server's timezone is correctly set. Cron jobs in Odoo are executed based on the server's timezone configuration. Verify that the timezone is set correctly in the Odoo configuration file (odoo.conf).


Avatar
Verwerfen
Beste Antwort

Sorry for the late response,
The print() function won't display anything in odoo log file.
You should use a logging function to display infos in odoo log.

See example below:

import logging
_logger=logging.getLogger(__name__) 
_logger.info("MY FIRST INFO LOG")

I hope I've helped you...

Avatar
Verwerfen
Beste Antwort

Hello,

For the XML code:

 


For the python code:

@api.model
def test_cron(self):
print("test cron")

Be sure that the xmlfile is imported in the _manifest.py and the python file is imported in the __init_.py file.

For the model_id in the xml file:

You have to set model.model_name where the model is the name of your application and model_name is the name of your model where the function test_cron is declared.


Best regards,

Imal-Tech
 
Imal-Tech team




Avatar
Verwerfen
Autor

The problem is I already added the xml file and python file to manifest and init. The cron job actually runs but it doesn't execute the function.

Autor

odoo_web | 2022-10-23 04:03:17,213 43 INFO merctrans odoo.addons.base.models.ir_cron: Starting job `Auto Sync Payment Status`.
odoo_web | 2022-10-23 04:03:17,215 43 INFO merctrans odoo.addons.base.models.ir_cron: Job `Auto Sync Payment Status` done.
odoo_web | 2022-10-23 04:04:20,286 43 INFO merctrans odoo.addons.base.models.ir_cron: Starting job `Auto Sync Payment Status`.
odoo_web | 2022-10-23 04:04:20,287 43 INFO merctrans odoo.addons.base.models.ir_cron: Job `Auto Sync Payment Status` done.
odoo_web | 2022-10-23 04:05:23,444 43 INFO merctrans odoo.addons.base.models.ir_cron: Starting job `Auto Sync Payment Status`.
odoo_web | 2022-10-23 04:05:23,451 43 INFO merctrans odoo.addons.base.models.ir_cron: Job `Auto Sync Payment Status` done.
odoo_web | 2022-10-23 04:06:26,610 43 INFO merctrans odoo.addons.base.models.ir_cron: Starting job `Auto Sync Payment Status`.
odoo_web | 2022-10-23 04:06:26,617 43 INFO merctrans odoo.addons.base.models.ir_cron: Job `Auto Sync Payment Status` done.
odoo_web | 2022-10-23 04:06:32,467 44 INFO merctrans odoo.addons.base.models.ir_cron: Starting job `Auto Sync Payment Status`.
odoo_web | 2022-10-23 04:06:32,481 44 INFO merctrans odoo.addons.base.models.ir_cron: Job `Auto Sync Payment Status` done.

You can see here that the cron job runs, but doesn't print anything to terminal

Hi, did you manage to fix it? or do you need help?

Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Mai 25
148
0
Mai 25
197
1
Mai 25
564
4
Mai 25
1861
2
Mai 25
2027