Creating a Scheduler


A scheduler executes a particular function at regular intervals, without human interference. Schedulers are automated actions that run automatically over a time period
In Odoo 8 you can find schedulers at "Settings>Technical>Automation>Scheduled Actions". scheduler belongs to the openerp model "ir.cron".
In order to create and execute Scheduler, Here I define steps.
Create a record for ir.cron model. That can be done by 2 ways.
1. You can direct go to menu "Settings>Technical>Automation>Scheduled Actions".
and then you can create your record.
2. Same record you create from your xml file. In order to do that, in your xml file add following kind of xml code,
<record model="ir.cron" id="account_modify_penalty">
<field name="name">Scheduler Name </field>
<field name="interval_number">1</field>
<field name="interval_type">months</field>#Interval Unit
<field name="numbercall">-1</field>#Number of Calls
<field name="doall" eval="False"/>#Repeat Missed
<field name="model" eval="'account.invoice'"/> ( Here you need to give the model in which you want to execute your method.)
<field name="function" eval="'YOUR CUSTOM FUNCTION'"/> ( Here give your custom function. )
<field name="args" eval="'()'" />
</record>
"scheduler_id" : is a unique xml record id
"scheduler_name" : any desirable name
"active" : True or False determines whether the scheduler is active or not..
"user_id" : refers the user who owns the scheduler
"interval_number" : number of times the scheduler is to be called based on the "interval_type"
"interval_type" : it can be days, hours, minututes ,monthsetc
"numbercall" : Number of time the function is called. negative number indicates no limit
"doall" : booelan field. A 'True' enables it to execute missed occurences as soon as the server is restarts
"model" : Name of object whose function will be called when this scheduler will run. e.g. 'res.partener'
"function" : Name of the method to be called on the object when this scheduler is executed.
"args" : Arguments to be passed to the method. e.g. (uid,)
<record id="ir_cron_mail_gateway_action" model="ir.cron">
<field name="name">Fetchmail JKP</field>
<field name="interval_number">3</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model">mail.compose.message</field>
<field name="function">send_script_mail</field>
<field name="args">()</field>
</record>

2) Create your custom function in any of model. As per step 1, put that function name and model over there.
def my_schedule(self,cr,uid,context):
// either give the code for your calculation for paid here or
// call to your calculation function from here

return True
3) In order to provide custom arguments, use "args" field.
4) Once you update your module, You can see your Schedule Action will be,
Settings>Technical>Automation>Scheduled Actions". menu.
Please note : The scheduled actions which are not active, they will not able to visible in list. You need to go to Advance search and find them.
Note:when you call any method from Scheduler, you can't pass Ids argument. Thats why you are getting error. Now If Ids argument is must needed in your function, then pass "False" from Schedular as Argument. For example, please see "Run MRP schedular" cron. You will see "(False,)" as in argument.

0 comments:

Copyright © 2013 SoftKul