odoo12 in regular tasks

To odoo12 example:

1. Define the timing task properties

<record id="ir_cron_submit_auto_action" model="ir.cron">

            <Field name = "name"> Auto Action </ field>

            <field name="model_id" ref="model_sale_order"/>

            <field name="state">code</field>

            <Field name = "code"> model.submit_auto_action () </ field> # task method, and mode_id decide together when the time comes the task, which method is called.

            <Field name = "interval_number"> 1 </ field> determines the task execution interval with # task execution frequency, and field interval_type

            <field name="interval_type">days</field>

            <Field name = "numbercall"> - 1 </ field> # (numbercall:. The number of cycles of operation, for example, you fill in 10, then the task will not be executed 10 times execution has been executed here -1 for down)

            <Field eval = "True" name = "doall" /> # If you missed the opportunity to perform during a server restart, whether supplemental executed again.

            <Field name = "user_id" ref = "base.user_root" /> User # task execution timing, different users have different privileges, in order to ensure to have sufficient rights to perform regular tasks, this is generally base.user_root

        </record>

2. Define the timing python code to be executed in python

Python corresponding method code corresponding model defined as follows:

def submit_auto_action(self):

        lines = self.env['sale.order'].search([])

        for r in lines:

            r.write({'state':'done'})


Thanks to the original reference link: https: //www.jianshu.com/p/76aa22c98476

Guess you like

Origin www.cnblogs.com/1314520xh/p/11873913.html