콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2500 화면

On Odoo16, I'm trying to create a cron job in code like this;

                self.env['ir.cron'].sudo().create({

                    'name': cron.cron_name,

                    'cron_name': cron.cron_name,

                    'active': False,

                    'interval_number': cron.interval_number,

                    'interval_type': cron.interval_type,

                    'numbercall': cron.numbercall,

                    'doall': cron.doall,

                    'model_id': cron.model_id,

                    'state': cron.state,

                    'code': cron.code.replace('{{store_id}}', str(self.id)),

                })

The cron job is created and I can see that the model_id is correct and referencing my model in ir.model. However, the cron job fails because "model_name" is NULL in ir_act_server. Looking at the model, the field is a stored related field as defined below;

model_name = fields.Char(related='model_id.model', string='Model Name', readonly=True, store=True)

If would seem that the related field is not being correctly set when a new record is created with model_id correctly set.

Most modules use XML to create cron jobs. I've checked and none of these attempt to explicitly set model_name, yet in the DB, model_name is correctly set for them.

If I manually edit the server action to change the model_id through the UI, the field is correctly updated.

Has anyone else seen this issue; whether specific to ir.action.server, or any related field not being set correctly?

아바타
취소
작성자 베스트 답변

Ok, got to the bottom of it. The value I was passing for the model_id was typed as char. This was fine for the DB as it implicitly converted it to an integer and the relationship to ir_model was correct, however the ORM didn't correctly relate this to ir.model at record creation. Changing the data type of the field cron.model_id to integer fixed the problem. Should it have been an integer in the first place? Yes. Should the related field have still worked? Yes; if the DB is happy with the relationship, then the ORM should be too.

아바타
취소
관련 게시물 답글 화면 활동
0
4월 22
4156
0
1월 17
4475
0
12월 15
4779
1
9월 15
17073
3
9월 23
11892