Skip to Content
Menu
This question has been flagged
3 Replies
7157 Views

My function like this:

class scheduler_demo(models.Model):
_name = 'scheduler.demo'
name = fields.Char(required=True)
numberOfUpdates = fields.Integer('Number of updates', help='The number of times the scheduler has run and updated this field')
lastModified = fields.Date('Last updated')

#This function is called when the scheduler goes off
def process_demo_scheduler_queue(self, cr, uid, context=None):
print('Thai123')
scheduler_line_obj = self.pool.get('scheduler.demo')
#Contains all ids for the model scheduler.demo
scheduler_line_ids = self.pool.get('scheduler.demo').search(cr, uid, [])
#Loops over every record in the model scheduler.demo
for scheduler_line_id in scheduler_line_ids :
#Contains all details from the record in the variable scheduler_line
scheduler_line =scheduler_line_obj.browse(cr, uid,scheduler_line_id ,context=context)
numberOfUpdates = scheduler_line.numberOfUpdates
#Prints out the name of every record.
_logger.info('line: ' + scheduler_line.name)
#Update the record
scheduler_line_obj.write(cr, uid, scheduler_line_id, {'numberOfUpdates': (numberOfUpdates +1), 'lastModified': datetime.date.today()}, context=context)


My XML like this:

Problem is why i cant call the function process_demo_scheduler_queue.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="ir_cron_scheduler_demo_action" model="ir.cron">
<field name="name">Demo scheduler</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">2</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_scheduler_demo"/>
<field eval="False" name="doall"/>
<field eval="'scheduler.demo'" name="model"/>
<field eval="'process_demo_scheduler_queue'" name="function"/>
</record>
</data>
</odoo>
Avatar
Discard

Which version you are using?

Author

Odoo11 community

Best Answer

remove the <data> tag if you are in V11 (not compulsory) and

remove noupdate="1" attribute otherwise, it's not got an update

and try this :


<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="ir_cron_scheduler_demo_action" model="ir.cron">
        <field name="name">Demo scheduler</field>
        <field name="interval_number">2</field>
        <field name="interval_type">minutes</field>
        <field name="numbercall">-1</field>
        <field name="doall" eval="False"/>
        <field name="model_id" ref="model_scheduler_demo"/>
        <field name="code">model.process_demo_scheduler_queue()</field> <!-- your python method name -->
        <field name="state">code</field>
    </record>
</odoo>

Avatar
Discard
Related Posts Replies Views Activity
9
Jun 23
11130
2
Jan 22
2733
2
Dec 21
6269
0
Jun 21
1007
0
Feb 21
1540