data = frappe.get_list("Bank Guarantee BG", filters={"status": "Open"})
for i in data:
d = frappe.get_doc("Bank Guarantee BG",i.name)
frappe.log_error(frappe.utils.date_diff(d.date_of_validity,frappe.utils.nowdate()))
if(frappe.utils.date_diff(d.date_of_validity,frappe.utils.nowdate()) < 30):
d.status = "Due for Expiry"
d.save()
elif(frappe.utils.date_diff(d.new_validity_date,frappe.utils.nowdate()) < 30):
d.status = "Due for Expiry"
d.save()
elif(frappe.utils.date_diff(d.new_validity_date,frappe.utils.nowdate()) == 0):
d.status = "Expired"
d.save()
Based on this we receive emails when a BG is about to expire, however i want to modify it, If my BG Status = Closed then it should not send any email, Even if the doc is about to expire. how can i modify that.
It gave me syntax error so i modified it via gpt, i hope this one is correct-
data = frappe.get_list("Bank Guarantee BG", filters={"status": "Open"})
for i in data:
d = frappe.get_doc("Bank Guarantee BG", i.name)
if d.status == "Closed":
continue
# Log the difference in dates
frappe.log_error(frappe.utils.date_diff(d.date_of_validity, frappe.utils.nowdate()))
# Check if the document is due for expiry
if frappe.utils.date_diff(d.date_of_validity, frappe.utils.nowdate()) < 30:
d.status = "Due for Expiry"
d.save()
elif frappe.utils.date_diff(d.new_validity_date, frappe.utils.nowdate()) < 30:
d.status = "Due for Expiry"
d.save()
elif frappe.utils.date_diff(d.new_validity_date, frappe.utils.nowdate()) == 0:
d.status = "Expired"
d.save()
If yes then should i wait for the mail ? or how can i manually check this script.