fix: Override template only if setting is enabled
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 405216b..d967100 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1108,7 +1108,8 @@
 				base_grand_total = flt(grand_total * self.get("conversion_rate"), self.precision("base_grand_total"))
 
 		if not self.get("payment_schedule"):
-			if self.doctype in ["Sales Invoice", "Purchase Invoice"] and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype):
+			if self.doctype in ["Sales Invoice", "Purchase Invoice"] and automatically_fetch_payment_terms \
+				and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype):
 				self.fetch_payment_terms_from_order(po_or_so, doctype)
 				if self.get('payment_terms_template'):
 					self.ignore_default_payment_terms_template = 1
diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js
index 54df0d6..4d432e3 100644
--- a/erpnext/public/js/utils/party.js
+++ b/erpnext/public/js/utils/party.js
@@ -76,7 +76,7 @@
 
 		if (args) {
 			args.posting_date = frm.doc.posting_date || frm.doc.transaction_date;
-			args.fetch_payment_terms_template = cint(!frm.doc.ignore_default_payment_terms_template)
+			args.fetch_payment_terms_template = cint(!frm.doc.ignore_default_payment_terms_template);
 		}
 	}
 	if (!args || !args.party) return;