This question has been flagged
1 Reply
4232 Views

I have been working to enable scheduler to call a particular function which will send alerts to the users of current forms. I am enabling this feature through settings->Technical->Scheduler->Scheduled Actions , but still my function is not called . I tried this to another simple function but no success. I am not sure where I am doing wrong. Please help me to fix this.

Regards

Avatar
Discard
Best Answer

Hi you can create a function in your py file and call the function in _data.xml which will run your scheduler.

Example:

Import the following in your py file:

import logging
from datetime import datetime
 _logger = logging.getLogger(__name__)

Create a function

def test_scheduler(self,cr,uid,ids=None,context=None):
    _logger.info("Scheduler Testing"+str(datetime.today()))
    return True

Create a yourmodule_data.xml file

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <record id="ir_cron_scheduler" model="ir.cron">
            <field name="name">Test Scheduler</field>
            <field name="interval_number">2</field>
            <field name="interval_type">minutes</field>
            <field name="numbercall">-1</field>
            <field eval="False" name="doall"/>
            <field eval="'yourmodelname'" name="model"/>
            <field eval="'test_scheduler'" name="function"/>
            <field eval="'()'" name="args"/>
        </record>
    </data>
</openerp>

Dont forget to import the xml file in __openerp__.py

Thanks

Avatar
Discard
Author

is this mandatory to use _logger = logging.getLogger(__name__) because I will no longer be using it

No. For this example i want the output to be printed on console log. So i imported tht. It depends on your need.

Author

no its still not working . have u tried it at your application ? because I m not getting anything on console

Ya its working fine with me. Did u get the scheduler name in web client?? U can verify that by Settings->Technical->Scheduler->Scheduled Actions, where u can find the scheduler name which was given in xml file.

Author

yes it worked . thanks I was making a big mistake