Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
3767 Представления

Impacted versions: 13

Steps to reproduce:
create cronjob:

<record id="my id" model="ir.cron">
            <field name="name">lol</field>
            <field name="model_id" ref="my_app.model_my_model"/>
            <field name="active" eval="False"/>
            <field name="user_id" ref="base.user_root"/>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="numbercall">-1</field>
            <field name="state">code</field>
            <field name="code">model.cron_blabla()</field>
            <field name="nextcall">2010-01-01 02:00:00</field>
        </record>

and my_model.py has :

@api.model
    def cron_blabla(self):
        running_jobs = self.env['some.model'].sudo().search([])

Current behavior:
No error in the log, but it doesn't do anything. The debugger can't retrieve the self value thus i can't perform the typical self.env['my.model'] and if i let it run i get an eternal odoo loading screen.

"running_jobs = self.env['some.model'].sudo().search()" accessing self here, is for some reason a problem.

Expected behavior:
The function should run, self.env['xyz'] should work


Help is highly appreciated


Special Hint/Edit:
I found out that the method is crashing as soon as it enters the function. The content of the first line doesn't play a role on the outcome

Аватар
Отменить
Лучший ответ

Do you have lots of records of the object you are searching the records? If yes, try by adding some limit in search method (limit=100)

When method is crashing, do you see any error / message in the log?

Аватар
Отменить
Лучший ответ

Hi, 

Should i suppose that you don't test your cron by running it manually ? Because i see clearly that active=False in your XML, so the cron won't never be triggered automatically. 

Аватар
Отменить
Лучший ответ

Hi,

Try changing your function like this

cron_obj = self.env['some.model']
running_jobs = cron_job.search([])

Regards

Аватар
Отменить