Jinja template in Terms and Conditions
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index c31b0c8..dcbb56b 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -902,13 +902,17 @@
get_terms: function() {
var me = this;
if(this.frm.doc.tc_name) {
- return this.frm.call({
- method: "frappe.client.get_value",
+ return frappe.call({
+ method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions',
args: {
- doctype: "Terms and Conditions",
- fieldname: "terms",
- filters: { name: this.frm.doc.tc_name },
+ template_name: this.frm.doc.tc_name,
+ doc: this.frm.doc
},
+ callback: function(r) {
+ if(!r.exc) {
+ me.frm.set_value("terms", r.message);
+ }
+ }
});
}
},
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
index ce057c2..bede595 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
@@ -16,6 +16,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "columns": 0,
"fieldname": "title",
"fieldtype": "Data",
"hidden": 0,
@@ -23,6 +24,7 @@
"ignore_xss_filter": 0,
"in_filter": 1,
"in_list_view": 0,
+ "in_standard_filter": 0,
"label": "Title",
"length": 0,
"no_copy": 1,
@@ -32,6 +34,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
+ "remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
@@ -42,6 +45,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "columns": 0,
"fieldname": "disabled",
"fieldtype": "Check",
"hidden": 0,
@@ -49,6 +53,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
+ "in_standard_filter": 0,
"label": "Disabled",
"length": 0,
"no_copy": 0,
@@ -57,6 +62,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
+ "remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
@@ -67,6 +73,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "columns": 0,
"fieldname": "terms",
"fieldtype": "Text Editor",
"hidden": 0,
@@ -74,6 +81,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
+ "in_standard_filter": 0,
"label": "Terms and Conditions",
"length": 0,
"no_copy": 0,
@@ -83,6 +91,36 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "terms_and_conditions_help",
+ "fieldtype": "HTML",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Terms and Conditions Help",
+ "length": 0,
+ "no_copy": 0,
+ "options": "<h4>Standard Terms and Conditions Example</h4>\n\n<pre>Delivery Terms for Order number {{ name }}\n\n-Order Date : {{ transaction_date }} \n-Expected Delivery Date : {{ delivery_date }}\n</pre>\n\n<h4>How to get fieldnames</h4>\n\n<p>The fieldnames you can use in your standard reply are the fields in the document from which you are sending the email. You can find out the fields of any documents via Setup > Customize Form View and selecting the document type (e.g. Sales Invoice)</p>\n\n<h4>Templating</h4>\n\n<p>Templates are compiled using the Jinja Templating Langauge. To learn more about Jinja, <a class=\"strong\" href=\"http://jinja.pocoo.org/docs/dev/templates/\">read this documentation.</a></p>",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
@@ -92,7 +130,7 @@
],
"hide_heading": 0,
"hide_toolbar": 0,
- "icon": "fa fa-legal",
+ "icon": "icon-legal",
"idx": 1,
"image_view": 0,
"in_create": 0,
@@ -101,7 +139,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-07-25 05:24:25.093905",
+ "modified": "2016-12-12 17:31:53.349301",
"modified_by": "Administrator",
"module": "Setup",
"name": "Terms and Conditions",
@@ -117,6 +155,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -137,6 +176,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 0,
"read": 1,
@@ -157,6 +197,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 0,
"read": 1,
@@ -177,6 +218,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -197,6 +239,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -217,6 +260,7 @@
"export": 0,
"if_owner": 0,
"import": 0,
+ "is_custom": 0,
"permlevel": 0,
"print": 0,
"read": 1,
@@ -231,5 +275,6 @@
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
+ "sort_order": "ASC",
"track_seen": 0
}
\ No newline at end of file
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
index 52f5156..d2b68b4 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -3,8 +3,18 @@
from __future__ import unicode_literals
import frappe
-
+import json
from frappe.model.document import Document
+from frappe.utils.jinja import validate_template
class TermsandConditions(Document):
- pass
\ No newline at end of file
+ def validate(self):
+ validate_template(self.terms)
+
+@frappe.whitelist()
+def get_terms_and_conditions(template_name, doc):
+ if isinstance(doc, basestring):
+ doc = json.loads(doc)
+
+ terms_and_conditions = frappe.get_doc("Terms and Conditions", template_name)
+ return frappe.render_template(terms_and_conditions.terms, doc)
\ No newline at end of file