Skip to Content
Menú
This question has been flagged
1 Respondre
15044 Vistes

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
Descartar
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
Descartar
Autor

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?

Autor

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 Respostes Vistes Activitat
4
de maig 24
12617
1
d’abr. 24
3259
1
de gen. 24
2289
0
de nov. 23
2001
1
de set. 23
2090