跳至内容
菜单
此问题已终结
1 回复
2110 查看

Good day All,


tl;dr - How do I reference the property Next Execution Date​in my Scheduled Action's python code?

I have a scheduled action that runs every day. However, there are days when all scheduled actions just kind of stopped running. Although that can be fixed easily with a server restart, the thing is once it stops, it would skip the previous days on when it should have run. Since we have a property called Next Execution Date​, along with Repeat Missed​ set to true, I figure if I can just reference that in the python code, then the issue regarding previous days would be fixed.


Regards,
Ariel



形象
丢弃
最佳答案

Hi,

You can handle missed executions within the same function, ensuring your scheduled action correctly references the "Next Execution Date" and handles any missed runs.

cron_record = self.env['ir.cron'].search([('name', '=', 'your_cron_job_name')], limit=1)

if cron_record:

next_execution_date = cron_record.nextcall

current_date = fields.Datetime.now()


# Check if there are missed executions

while next_execution_date

# your custom code

# Adjust based on the frequency of your scheduled action

next_execution_date += timedelta(days=1)

# Update the nextcall field to the next scheduled date

cron_record.write({'nextcall': next_execution_date})


Hope it helps

形象
丢弃
相关帖文 回复 查看 活动
2
2月 24
1792
0
8月 24
409
2
1月 24
897
1
5月 23
1148
3
7月 23
1649