Custom fields expiry dates of Licenses

Dear All
any way to create custom fields for storing license numbers [eg: drug or FSSAI] & expiry date
same to be checked at the time of sales invoice entry and notify if date is valid

also same to be available in a separate report to send reminders ‘x’ days before expiry
Regards
Frz

anyone?

Hi @Frz:

I don’t know about the business logic appliable to this … but, maybe this license numbers & expiry dates are for serial numbers or batches. So, should consider to customize batch/serial number doctype, and custom logic for check if dates are valid at invoicing time with a client script.

Hope this helps.

thanks for the response.
but the license is of the customer & not the item.
Regards
Frz

Hi @Frz:

There are many ways to approach this, depending on requirements:

Customize your “Customer” doctype, adding a field: “license_expiry_date”
Create a client script for “Sales Invoice” doctype (remember to enable it)

frappe.ui.form.on('Sales Invoice', {
	posting_date(frm) {
	    checkLicense(frm);
	},
	customer(frm){
	    checkLicense(frm);
	}
})

function checkLicense(frm) {
    frappe.db.get_value("Customer", frm.doc.customer, "custom_license_expiry_date", 
	    (r) => {
	       if (frm.doc.posting_date > r.license_expiry_date){
	           msgprint("Expired license!")
	       }
	    });
}

Note: version 15 automatically adds “custom_” prefix to custom field names, so
use if (frm.doc.posting_date > r.custom_license_expiry_date) instead if you are using v15 or develop branch.

To get automatic reminder, use “Notification”

Hope this helps.

1 Like

Thankyou
this works

1 Like

@avc
can we auto create a task on set alert?

Hi @Frz:

Notification just … notifies :slight_smile:

But automate ToDo is pretty simple.
Create a server script, type “Scheduler Event” with Daily frequency.

customers = frappe.db.sql("""select name, custom_license_expiry_date from `Customer` where DATEDIFF(custom_license_expiry_date,CURRENT_DATE)=7""", as_list=1)

for customer in customers:
        task = frappe.get_doc({
            "doctype": "ToDo",
            "due_date": customer.custom_license_expiry_date,
            "description": "Renew license " + customer.name,
            "reference_type": "Customer",
            "reference_name": customer.name
            })
        task.insert()
    

This way, each day the script create todo taks for renew licenses wich expires in 7 days.
Hope this helps.

2 Likes

Thankyou