feat: Supplier Email Preview in RFQ
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 4a937f7..4632757 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -22,8 +22,6 @@
},
onload: function(frm) {
- frm.add_fetch('email_template', 'response', 'message_for_supplier');
-
if(!frm.doc.message_for_supplier) {
frm.set_value("message_for_supplier", __("Please supply the specified items at the best possible rates"))
}
@@ -194,6 +192,56 @@
});
});
dialog.show()
+ },
+
+ preview: (frm) => {
+ let dialog = new frappe.ui.Dialog({
+ title: __('Preview Email'),
+ fields: [
+ {
+ label: __('Supplier'),
+ fieldtype: 'Select',
+ fieldname: 'supplier',
+ options: frm.doc.suppliers.map(row => row.supplier),
+ reqd: 1
+ },
+ {
+ fieldtype: 'Column Break',
+ fieldname: 'col_break_1',
+ },
+ {
+ label: __('Subject'),
+ fieldtype: 'Data',
+ fieldname: 'subject',
+ read_only: 1
+ },
+ {
+ fieldtype: 'Section Break',
+ fieldname: 'sec_break_1',
+ hide_border: 1
+ },
+ {
+ label: __('Email'),
+ fieldtype: 'HTML',
+ fieldname: 'email_preview',
+ },
+ ]
+ });
+
+ dialog.fields_dict['supplier'].df.onchange = () => {
+ var args = {
+ 'supplier' : dialog.get_value('supplier'),
+ 'salutation' : frm.doc.salutation || null,
+ 'message' : frm.doc.message_for_supplier
+ }
+ frm.call('get_supplier_email_preview', args).then(result => {
+ dialog.fields_dict.email_preview.$wrapper.empty();
+ dialog.fields_dict.email_preview.$wrapper.append(result.message);
+ });
+
+ }
+ dialog.set_value("subject", frm.doc.subject);
+ dialog.show();
}
})
@@ -276,7 +324,7 @@
})
}, __("Get items from"));
// Get items from Opportunity
- this.frm.add_custom_button(__('Opportunity'),
+ this.frm.add_custom_button(__('Opportunity'),
function() {
erpnext.utils.map_current_doc({
method: "erpnext.crm.doctype.opportunity.opportunity.make_request_for_quotation",
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
index 5cd8e6f..715556c 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -1,5 +1,5 @@
{
- "actions": "",
+ "actions": [],
"allow_import": 1,
"autoname": "naming_series:",
"creation": "2016-02-25 01:24:07.224790",
@@ -19,7 +19,12 @@
"items",
"link_to_mrs",
"supplier_response_section",
+ "salutation",
"email_template",
+ "col_break_email_1",
+ "subject",
+ "preview",
+ "sec_break_email_2",
"message_for_supplier",
"terms_section_break",
"tc_name",
@@ -126,8 +131,10 @@
"label": "Link to Material Requests"
},
{
+ "depends_on": "eval:!doc.__islocal",
"fieldname": "supplier_response_section",
- "fieldtype": "Section Break"
+ "fieldtype": "Section Break",
+ "label": "Email Details"
},
{
"fieldname": "email_template",
@@ -137,6 +144,8 @@
"print_hide": 1
},
{
+ "fetch_from": "email_template.response",
+ "fetch_if_empty": 1,
"fieldname": "message_for_supplier",
"fieldtype": "Text Editor",
"in_list_view": 1,
@@ -230,12 +239,41 @@
"options": "Request for Quotation",
"print_hide": 1,
"read_only": 1
+ },
+ {
+ "fetch_from": "email_template.subject",
+ "fetch_if_empty": 1,
+ "fieldname": "subject",
+ "fieldtype": "Data",
+ "label": "Subject"
+ },
+ {
+ "description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
+ "fieldname": "salutation",
+ "fieldtype": "Link",
+ "label": "Salutation",
+ "options": "Salutation"
+ },
+ {
+ "fieldname": "col_break_email_1",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "preview",
+ "fieldtype": "Button",
+ "label": "Preview Email"
+ },
+ {
+ "depends_on": "eval:!doc.__islocal",
+ "fieldname": "sec_break_email_2",
+ "fieldtype": "Section Break",
+ "hide_border": 1
}
],
"icon": "fa fa-shopping-cart",
"is_submittable": 1,
"links": [],
- "modified": "2020-06-25 14:37:21.140194",
+ "modified": "2020-09-28 14:25:31.357817",
"modified_by": "Administrator",
"module": "Buying",
"name": "Request for Quotation",
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
index b54a585..c3f69d7 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -62,6 +62,31 @@
def on_cancel(self):
frappe.db.set(self, 'status', 'Cancelled')
+ def get_supplier_email_preview(self, args):
+ rfq_suppliers = list(filter(lambda row: row.supplier == args.get('supplier'), self.suppliers))
+ rfq_supplier = rfq_suppliers[0].as_dict()
+
+ update_password_link = self.update_supplier_contact(rfq_supplier, self.get_link())
+
+ full_name = get_user_fullname(frappe.session['user'])
+ if full_name == "Guest":
+ full_name = "Administrator"
+
+ args = {
+ 'update_password_link': update_password_link,
+ 'message': frappe.render_template(self.message_for_supplier, args),
+ 'rfq_link': self.get_link(),
+ 'user_fullname': full_name,
+ 'supplier': rfq_supplier.supplier_name,
+ 'salutation': args.get('salutation')
+ }
+ args.update(self.as_dict())
+
+ subject = _("Request for Quotation")
+ template = "templates/emails/request_for_quotation.html"
+ message = frappe.get_template(template).render(args)
+ return message
+
def send_to_supplier(self):
for rfq_supplier in self.suppliers:
if rfq_supplier.send_email:
diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html
index b4dfb88..414dd0f 100644
--- a/erpnext/templates/emails/request_for_quotation.html
+++ b/erpnext/templates/emails/request_for_quotation.html
@@ -1,11 +1,24 @@
-<h3>{{_("Request for Quotation")}}</h3>
+<h4>{{_("Request for Quotation")}}</h4>
+<p>{{_("Dear")}} {{ salutation if salutation else ''}} {{ supplier }},</p>
<p>{{ message }}</p>
-{% if update_password_link %}
-<p>{{_("Please click on the following link to set your new password")}}:</p>
-<p><a href="{{ update_password_link }}">{{ update_password_link }}</a></p>
-{% else %}
+
<p>{{_("The request for quotation can be accessed by clicking on the following link")}}:</p>
-<p><a href="{{ rfq_link }}">Submit your Quotation</a></p>
-{% endif %}
-<p>{{_("Thank you")}},<br>
-{{ user_fullname }}</p>
+<p>
+ <button style="border: 1px solid #15c; padding: 6px; border-radius: 5px; background-color: white;">
+ <a href="{{ rfq_link }}" style="color: #15c" target="_blank">Submit your Quotation</a>
+ </button>
+</p><br>
+
+<p>{{_("Regards")}},<br>
+{{ user_fullname }}</p><br>
+
+{% if update_password_link %}
+<div>
+<p>{{_("Please click on the following link to set your new password")}}:</p>
+<p>
+ <button style="border: 1px solid #15c; padding: 4px; border-radius: 5px; background-color: white;">
+ <a href="{{ update_password_link }}" style="color: #15c; font-size: 12px;" target="_blank">{{_("Update Password") }}</a>
+ </button>
+</p>
+</div>
+{% endif %}
\ No newline at end of file