refactor: DRY for disable due date logic
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index abd5566..4650345 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -52,7 +52,14 @@
 	},
 	taxes_on_form_rendered: function(frm) {
 		erpnext.taxes.set_conditional_mandatory_rate_or_amount(frm.open_grid_row());
-	}
+	},
+
+	disable_due_date: function() {
+		const disable = cur_frm.doc.payment_terms_template || (
+							cur_frm.doc.payment_schedule && cur_frm.doc.payment_schedule.length != 0);
+		cur_frm.set_df_property("due_date", "read_only", disable ? 1 : 0);
+	},
+
 });
 
 frappe.ui.form.on('Sales Invoice Payment', {
@@ -62,15 +69,32 @@
 			frappe.model.set_value(cdt, cdn, 'account', account)
 		})
 	}
-})
+});
+
+frappe.ui.form.on("Sales Invoice", {
+	payment_terms_template: function() {
+		cur_frm.trigger("disable_due_date");
+	}
+});
 
 frappe.ui.form.on('Purchase Invoice', {
 	mode_of_payment: function(frm) {
 		get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){
 			frm.set_value('cash_bank_account', account);
 		})
+	},
+
+	payment_terms_template: function() {
+		cur_frm.trigger("disable_due_date");
 	}
-})
+});
+
+frappe.ui.form.on("Payment Schedule", {
+	payment_schedule_remove: function() {
+		cur_frm.trigger("disable_due_date");
+	},
+
+});
 
 frappe.ui.form.on('Payment Entry', {
 	mode_of_payment: function(frm) {