I try to create server script scheduler event to automatically STOP material request documents that have a required date of more than 2 days from the current date.
Here’s the script I use :
material_requests = frappe.get_all('Material Request', filters = {'status': 'Partially Ordered'}, fields = ['name'])
now_date = str(frappe.utils.nowdate())
for row in material_requests:
if row.schedule_date:
schedule_date = frappe.utils.data.getdate(str(row.schedule_date))
if now_date > frappe.utils.data.add_days(schedule_date, 2):
mr = frappe.get_doc('Material Request', row.name)
mr.status = "Stopped"
mr.save()
The script can be executed without errors but does not change the status of the material request.
Please help me with this?
Try debugging using frappe.log_error() within the if conditions, to see if the conditions are being satisfied (also use logs of the date variables, to see if they are what you expect them to be).
My guess would be the now_date and schedule date comparison, one is str while the other is a date time object?