Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
15016 Переглядів

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'})"
Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Автор

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?

Автор

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 Відповіді Переглядів Дія
4
трав. 24
12615
1
квіт. 24
3251
1
січ. 24
2284
0
лист. 23
1996
1
вер. 23
2084