Hello,
The bellow code inserts data from another database into postgres table product.public.category.
My goal is to run this on a scheduler. I've configured a cron job to run every hour for this method.
The cron job executes python code: model.get_grupe() . The issues here is that the code does not get executed on the cron instead if i click on Run Manually button from the cron, it will work.
What can I do to make it work on the scheduler ?
Odoo 13 CE.
def get_grupe(self):
lst = self.get_from_borg('GrupeProduse')
grupe = self.env['product.public.category'].search([])
for item in lst:
it = item.split('\t')
if it[0].isdigit():
id_cat = it[0]
name_categ = it[1].title()
type = it[2]
id_ramura = it[3]
name_ramura = it[4].title()
parent_id = False
ramura = grupe.search(
[('parent_id', '=', False), ('id2', '=', id_ramura)])
if ramura:
parent_id = ramura[0].id
ramura[0].name = name_ramura
else:
ramura = self.env['product.public.category'].create({
'id2': id_ramura,
'name': name_ramura,
'parent_id': False
})
parent_id = ramura.id
grupa = grupe.search([('parent_id', '!=', False) ,('id2', '=', id_cat)])
if grupa:
grupa[0].write({
'name': name_categ,
'parent_id': parent_id
})
else:
self.env['product.public.category'].create({
'id2': id_cat,
'name': name_categ,
'parent_id': parent_id
})
Thank you.
Can you please add your scheduler code.
<record id="sync_categories" model="ir.cron">
<field name="interval_type">hours</field>
<field name="interval_number">2</field>
<field name="name">Sync categories</field>
<field name="user_id" ref="base.user_root"/>
<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_id" ref="model_borg_client"/>
<field name="state">code</field>
<field name="code">model.get_grupe()</field>
</record>