Skip to Content
Menu
This question has been flagged
1 Atsakyti
2099 Rodiniai

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



Portretas
Atmesti
Best Answer

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

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
2
vas. 24
1782
0
rugp. 24
402
2
saus. 24
886
1
geg. 23
1148
3
liep. 23
1647