Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
2576 Visninger

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



Avatar
Kassér
Bedste svar

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

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
2
feb. 24
2745
1
jul. 25
745
2
jan. 24
1331
1
maj 23
1537
3
jul. 23
2205