Default payment due date setup issue


I have created a custom script to set default payment due date in Sales Invoice as 15 days from posting date.

When I open a new sales invoice form it shows proper date. But when I select customer then payment due date will be updated as posting date itself.

Custom script-

frappe.ui.form.on(‘Sales Invoice’, ‘onload’, function(frm){
frm.set_value(“due_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), 15));


Please help me in this issue.

Thanks & Regards,

Please try using Payment Terms instead?