ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Sales Invoice - Item Expiry Notification

Hello every one
I’m new to ERPNext; please help me with this.

I would like to create a sales invoice for an item that expired soon and also to show an alert message “it expires soon”.

a server script code is written in the sales invoice for that:

for item in doc.items:
if item.expiry_date and frappe.utils.date_diff(frappe.utils.today(), item.expiry_date) <= 30:
frappe.msgprint( msg= item.item_code + ’ will expire on '+item.expiry_date, title=‘Item(s) Expire Soon’)

But it does not work.
Please help me with this.