Modification in server script

Hi Everyone,

I have a server script for my erpnext v-15

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.

Thank You

Linked Scheduled Job Type

Anyone ?

@rs115199789
try this

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
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()

Hi, @Jeel

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.

Thank You

@rs115199789 yes there is some indentation issue i want to add but i forgot it

No problem i will then just wait for the mail to see the results.