Search code examples
odooodoo-13

Why is odoo schedule automation not working


I currently created a module needed to work with cronjob. I've follow the code and step found from online to set the cronjob, but it doesn't work like what the result show online. I found the cronjob did run, but not calling the method I declare in the ir.cron I not sure it is any step I doing wrong. Below is my sample code.

data.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data noupdate="1">
        <record id="ir_cron_test_cronjob" model="ir.cron">
            <field name="name">Test Cronjob</field>
            <field name="model_id" ref="model_mymod_testingmodel" />
            <field name="user_id" ref="base.user_root"/>
            <field name="state">code</field>
            <field name="code">model.testing_method()</field>
            <field name="interval_number">1</field>
            <field name="interval_type">minutes</field>
            <field name="numbercall">-1</field>
            <field name="doall" eval="False" />
            <field name="active" eval="True" />                    
        </record>
    </data>
</openerp>

mymod.py

from odoo import models,api,fields,_
import requests

class TestingModel(models.Model):
    _name="mymod.testingmodel"

    @api.model
    def testing_method(self):
        print("Enter testing_method")
        requests.get("http://localhost/testing/simple_log.php?text=odoo13")


Solution

  • I solved my problem with change noupdate value to 0 for my case. According to Kenly explain, noupdate="1" is for cron only apply for once.

    data.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <openerp>
        <data noupdate="0">
            <record id="ir_cron_test_cronjob" model="ir.cron">
                <field name="name">Test Cronjob</field>
                <field name="model_id" ref="model_mymod_testingmodel" />
                <field name="user_id" ref="base.user_root"/>
                <field name="state">code</field>
                <field name="code">model.testing_method()</field>
                <field name="interval_number">1</field>
                <field name="interval_type">minutes</field>
                <field name="numbercall">-1</field>
                <field name="doall" eval="False" />
                <field name="active" eval="True" />                    
            </record>
        </data>
    </openerp>