[enhancement] standard replies now support jinja templating, fixes frappe/erpnext#4787
This commit is contained in:
parent
b9f1d6cee1
commit
0c7e476ff3
5 changed files with 94 additions and 24 deletions
|
|
@ -437,7 +437,7 @@
|
|||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Depends On",
|
||||
"label": "Display Depends On",
|
||||
"length": 255,
|
||||
"no_copy": 0,
|
||||
"oldfieldname": "depends_on",
|
||||
|
|
@ -1012,7 +1012,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-02-22 09:08:47.112186",
|
||||
"modified": "2016-03-22 15:18:41.237995",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "DocField",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Subject",
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
|
|
@ -39,6 +41,7 @@
|
|||
"fieldtype": "Text Editor",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Response",
|
||||
|
|
@ -46,6 +49,7 @@
|
|||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
|
|
@ -62,6 +66,7 @@
|
|||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Owner",
|
||||
|
|
@ -70,6 +75,57 @@
|
|||
"options": "User",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "section_break_4",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "standard_reply_help",
|
||||
"fieldtype": "HTML",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Standard Reply Help",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "<h4>Standard Reply Example</h4>\n\n<pre>Order Overdue\n\nTransaction {{ doc.name }} has exceeded Due Date. Please take necessary action.\n\nDetails\n\n- Customer: {{ doc.customer }}\n- Amount: {{ doc.grand_total }}\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>\n",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
|
|
@ -81,13 +137,14 @@
|
|||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"icon": "icon-comment",
|
||||
"idx": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-11-16 06:29:57.875243",
|
||||
"modified": "2016-03-22 15:25:43.935671",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Email",
|
||||
"name": "Standard Reply",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,17 @@
|
|||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import frappe, json
|
||||
from frappe.model.document import Document
|
||||
|
||||
class StandardReply(Document):
|
||||
pass
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_standard_reply(template_name, doc):
|
||||
'''Returns the processed HTML of a standard reply with the given doc'''
|
||||
if isinstance(doc, basestring):
|
||||
doc = json.loads(doc)
|
||||
|
||||
standard_reply = frappe.get_doc("Standard Reply", template_name)
|
||||
return frappe.render_template(standard_reply.response, doc)
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Letter Head Name",
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Disabled",
|
||||
|
|
@ -69,6 +71,7 @@
|
|||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Is Default",
|
||||
|
|
@ -96,6 +99,7 @@
|
|||
"fieldtype": "Text Editor",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Content",
|
||||
|
|
@ -117,10 +121,12 @@
|
|||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"depends_on": "letter_head_name",
|
||||
"fieldname": "footer",
|
||||
"fieldtype": "Text Editor",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Footer",
|
||||
|
|
@ -148,7 +154,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 3,
|
||||
"modified": "2016-01-28 02:03:23.139628",
|
||||
"modified": "2016-03-22 15:18:09.648844",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Print",
|
||||
"name": "Letter Head",
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ frappe.views.CommunicationComposer = Class.extend({
|
|||
var me = this;
|
||||
this.dialog.get_input("standard_reply").on("change", function() {
|
||||
var standard_reply = $(this).val();
|
||||
var prepend_reply = function() {
|
||||
|
||||
var prepend_reply = function(reply_html) {
|
||||
if(me.reply_added===standard_reply) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -149,30 +150,27 @@ frappe.views.CommunicationComposer = Class.extend({
|
|||
parts = content.split('<!-- salutation-ends -->');
|
||||
|
||||
if(parts.length===2) {
|
||||
content = [parts[0], frappe.standard_replies[standard_reply],
|
||||
"<br>", parts[1]];
|
||||
content = [reply_html, "<br>", parts[1]];
|
||||
} else {
|
||||
content = [frappe.standard_replies[standard_reply],
|
||||
"<br>", content];
|
||||
content = [reply_html, "<br>", content];
|
||||
}
|
||||
|
||||
content_field.set_input(content.join(''));
|
||||
|
||||
me.reply_added = standard_reply;
|
||||
}
|
||||
if(frappe.standard_replies[standard_reply]) {
|
||||
prepend_reply();
|
||||
} else {
|
||||
$.ajax({
|
||||
url:"/api/resource/Standard Reply/" + standard_reply,
|
||||
statusCode: {
|
||||
200: function(data) {
|
||||
frappe.standard_replies[standard_reply] = data.data.response;
|
||||
prepend_reply();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
frappe.call({
|
||||
method: 'frappe.email.doctype.standard_reply.standard_reply.get_standard_reply',
|
||||
args: {
|
||||
template_name: standard_reply,
|
||||
doc: me.frm.doc
|
||||
},
|
||||
callback: function(r) {
|
||||
prepend_reply(r.message);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue