Skip to Content
Menu
This question has been flagged
1 Reply
13397 Views

I'm trying to create a ir.cron and that cron do something depending on a condition, but no success:

Code:

for record in records:
if record.name == '000000156':
record.write({'name': '!00000156'})

Error:

return unsafe_eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
ValueError: <class 'TypeError'>: "'NoneType' object is not iterable" while evaluating
"for record in records:\n  if record.name == '000000156':\n    record.write({'name': '!00000156'})"
Avatar
Discard
Best Answer

Hi,

Check below for reference for creating a basic ir.cron

<?xml version="1.0" ?>
<odoo>
 <data noupdate="1">
   <record id="backup_scheduler" model="ir.cron">
     <field name="function">schedule_backup</field>
     <field name="interval_type">work_days</field>
     <field name="name">Backup scheduler</field>
     <field name="numbercall">-1</field>
     <field name="priority">5</field>
     <field name="doall">False</field>
     <field name="active">False</field>
     <field name="interval_number">1</field>
     <field name="model">db.backup</field>
   </record>
 </data>
</odoo>

Here schedule_backup is the function and db.backup is the model, you can write the functions for manipulation in schedule_backup. For More reference visit Automated action in Odoo

The error above indicates the null data in records

Hope it helps

Avatar
Discard
Author

I know how to create a ir.cron, that's not the question. How can I manipulate records throught ir.cron by using python code, something like:

if recor.name == something: do something else.

That's the question. I know that its possible to do that by using server action, but how it workds by using cron?

Author

Okay I found a way. Looks like that ir.cron works on model level, in order to manipulte records, i need to call a method(model.my_method) on my cron and on that method, do self.search and then manipulate the records on it. Thanks anyway.

Related Posts Replies Views Activity
4
May 24
10062
1
Apr 24
1560
1
Jan 24
576
0
Nov 23
522
1
Sep 23
558