Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
15024 Vistas

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
Mejor respuesta

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.

Publicaciones relacionadas Respuestas Vistas Actividad
4
may 24
12616
1
abr 24
3256
1
ene 24
2285
0
nov 23
1997
1
sept 23
2088