Skip to Content
Menú
This question has been flagged
3 Respostes
10856 Vistes

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.

Avatar
Descartar

Can you please add your scheduler code.

Autor

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

Autor Best Answer

Issue solved, the problem was because of the translations. I was updating only the category name  in the product categories table and I  had to update the translation for the category as well in the ir.translation table.

Avatar
Descartar

i have the same problem but what you say is not the solution :(

Best Answer

Hi, you can follow this link for this:

https://youtu.be/iBvtwy8x_E0

Hope it helps,

Thanks

Avatar
Descartar
Best Answer


Check Preference --> Timezone  = Current user timezone.

If other timezone may be delay to auto execute.

or you can debug code adding _logger in your cron job method.

import logging
_logger = logging.getLogger(__name__)

_logger.warning('Cron Job testing')


Avatar
Descartar
Autor

The job executes when it should. So, my code updates data in product_public_category table. I've deleted all records in the table and now the table gets populated at the right time, every time without deleting the data in the table anymore. However I cannot delete the data in the production database just to make the scheduler work. I need to find another solution.

Related Posts Respostes Vistes Activitat
0
d’oct. 24
1569
1
d’ag. 24
4518
0
de maig 21
3003
2
de gen. 25
2109
1
de maig 24
6429