Wednesday, July 10, 2019

create scheduler in odoo

ODOO

Before showing how to create auto action or scheduler in odoo let me give a Definition of what is the scheduler 

scheduler is a function called automatically by the system it self 



I think now you can guess the way of creating scheduler , yes it's by two steps 
  • create my function which can make the job I need , if it called 
  • create the way which make the system call that function automatically by time 
Now let me give an example of creating scheduler 
  • create function 
      @api.one
      def get_
even_numbers(self): 

       """ this function return the even numbers between 0 - 11 """
        
            even_list = [2,4,6,8,10]
            return even_list

  • create auto action
      <?xml version="1.0" encoding="utf-8"?>
      <openerp>
            <data noupdate="1">
                   <record id="ir_cron_scheduler_demo_action" model="ir.cron">
                          <field name="name">Even Number Scheduler</field>
                          <field name="user_id" ref="base.user_root"/>
                          <field name="interval_number">15</field>
                          <field name="interval_type">days</field>
                          <field name="numbercall">-1</field>
                          <field eval="False" name="doall"/>
                          <field eval="'even_number.scheduler'" name="model"/>
                          <field eval="'
get_even_numbers'" name="function"/>
                  </record>
           </data>
     </openerp> 

Now let me explain what that means 
  • first I create python file which contain get_even_numbers function which make what I wanna do 
  • create xml file that call my method every 15 days 

<record id="ir_cron_scheduler_demo_action" model="ir.cron"> // here I make id for my scheduler record 

<field name="user_id" ref="base.user_root"/> // define the user

<field name="interval_number">15</field> //  define number of time units that I wanna call me function after it 

<field name="interval_type">days</field> // define the time unit

<field name="numbercall">-1</field> // counter for number of calls and I set it for -1 to call my function for ever 

<field eval="False" name="doall"/> // set false value for doall

<field eval="'even_number.scheduler'" name="model"/> //  here I refers to my python file which contain my function 

<field eval="'get_even_numbers'" name="function"/> // here I put the function which I wanna call by the scheduler

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...