Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
15013 Widoki

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'})"
Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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.

Powiązane posty Odpowiedzi Widoki Czynność
4
maj 24
12615
1
kwi 24
3250
1
sty 24
2284
0
lis 23
1996
1
wrz 23
2084