fix: Reuse function to render email preview
- Reused `supplier_rfq_mail` to render preview
- Print hid Salutation and Subject
- Completely dynamic greeting
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 4632757..880a4cd 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -213,7 +213,8 @@
label: __('Subject'),
fieldtype: 'Data',
fieldname: 'subject',
- read_only: 1
+ read_only: 1,
+ depends_on: 'subject'
},
{
fieldtype: 'Section Break',
@@ -229,12 +230,8 @@
});
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 => {
+ var supplier = dialog.get_value('supplier');
+ frm.call('get_supplier_email_preview', {supplier: supplier}).then(result => {
dialog.fields_dict.email_preview.$wrapper.empty();
dialog.fields_dict.email_preview.$wrapper.append(result.message);
});
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 715556c..7e5650f 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -245,14 +245,17 @@
"fetch_if_empty": 1,
"fieldname": "subject",
"fieldtype": "Data",
- "label": "Subject"
+ "label": "Subject",
+ "print_hide": 1
},
{
"description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
"fieldname": "salutation",
"fieldtype": "Link",
"label": "Salutation",
- "options": "Salutation"
+ "no_copy": 1,
+ "options": "Salutation",
+ "print_hide": 1
},
{
"fieldname": "col_break_email_1",
@@ -273,7 +276,7 @@
"icon": "fa fa-shopping-cart",
"is_submittable": 1,
"links": [],
- "modified": "2020-09-28 14:25:31.357817",
+ "modified": "2020-09-28 17:37:10.313350",
"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 c3f69d7..5c9b91e 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -62,29 +62,15 @@
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()
+ def get_supplier_email_preview(self, supplier):
+ # Returns formatted email preview as string
+ rfq_suppliers = list(filter(lambda row: row.supplier == supplier, self.suppliers))
+ rfq_supplier = rfq_suppliers[0]
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"
+ message = self.supplier_rfq_mail(rfq_supplier, update_password_link, self.get_link(), True)
- 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):
@@ -154,7 +140,7 @@
return user, update_password_link
- def supplier_rfq_mail(self, data, update_password_link, rfq_link):
+ def supplier_rfq_mail(self, data, update_password_link, rfq_link, preview=False):
full_name = get_user_fullname(frappe.session['user'])
if full_name == "Guest":
full_name = "Administrator"
@@ -163,13 +149,19 @@
'update_password_link': update_password_link,
'message': frappe.render_template(self.message_for_supplier, data.as_dict()),
'rfq_link': rfq_link,
- 'user_fullname': full_name
+ 'user_fullname': full_name,
+ 'supplier_name' : data.get('supplier_name'),
+ 'supplier_salutation' : self.salutation or 'Dear Mx.',
}
- subject = _("Request for Quotation")
+ subject = self.subject or _("Request for Quotation")
template = "templates/emails/request_for_quotation.html"
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
message = frappe.get_template(template).render(args)
+
+ if preview:
+ return message
+
attachments = self.get_attachments()
self.send_email(data, sender, subject, message, attachments)
diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html
index 414dd0f..216bd81 100644
--- a/erpnext/templates/emails/request_for_quotation.html
+++ b/erpnext/templates/emails/request_for_quotation.html
@@ -1,11 +1,11 @@
<h4>{{_("Request for Quotation")}}</h4>
-<p>{{_("Dear")}} {{ salutation if salutation else ''}} {{ supplier }},</p>
+<p>{{ supplier_salutation if supplier_salutation else ''}} {{ supplier_name }},</p>
<p>{{ message }}</p>
-<p>{{_("The request for quotation can be accessed by clicking on the following link")}}:</p>
+<p>{{_("The Request for Quotation can be accessed by clicking on the following button")}}:</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>
+ <a href="{{ rfq_link }}" style="color: #15c; text-decoration:none;" target="_blank">Submit your Quotation</a>
</button>
</p><br>
@@ -14,10 +14,10 @@
{% if update_password_link %}
<div>
-<p>{{_("Please click on the following link to set your new password")}}:</p>
+<p>{{_("Please click on the following button 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>
+ <a href="{{ update_password_link }}" style="color: #15c; font-size: 12px; text-decoration:none;" target="_blank">{{_("Update Password") }}</a>
</button>
</p>
</div>