thunq
January 31, 2024, 6:36am
1
I am currently working on setting up automation in ERPNext to automatically change the status of tasks to ‘Overdue’ once their expected end date has passed, any advice ?
NCP
January 31, 2024, 6:50am
2
Hi @thunq ,
Here, we share the reference of the code, and how it works.
def set_tasks_as_overdue():
tasks = frappe.get_all(
"Task",
filters={"status": ["not in", ["Cancelled", "Completed"]]},
fields=["name", "status", "review_date"],
)
for task in tasks:
if task.status == "Pending Review":
if getdate(task.review_date) > getdate(today()):
continue
frappe.get_doc("Task", task.name).update_status()
def update_status(self):
if self.status not in ("Cancelled", "Completed") and self.exp_end_date:
from datetime import datetime
if self.exp_end_date < datetime.now().date():
self.db_set("status", "Overdue", update_modified=False)
self.update_project()
I hope this helps.
Thank You!
thunq
January 31, 2024, 11:18pm
3
Thank you, I will give it a try.