feat(RFQ): make email message fully configurable (#36353)
feat: make RFQ message fully configurable
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 0cdb915..31a06cf 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -244,19 +244,21 @@
]
});
- dialog.fields_dict['supplier'].df.onchange = () => {
- var supplier = dialog.get_value('supplier');
- frm.call('get_supplier_email_preview', {supplier: supplier}).then(result => {
+ dialog.fields_dict["supplier"].df.onchange = () => {
+ frm.call("get_supplier_email_preview", {
+ supplier: dialog.get_value("supplier"),
+ }).then(({ message }) => {
dialog.fields_dict.email_preview.$wrapper.empty();
- dialog.fields_dict.email_preview.$wrapper.append(result.message);
+ dialog.fields_dict.email_preview.$wrapper.append(
+ message.message
+ );
+ dialog.set_value("subject", message.subject);
});
-
- }
+ };
dialog.fields_dict.note.$wrapper.append(`<p class="small text-muted">This is a preview of the email to be sent. A PDF of the document will
automatically be attached with the email.</p>`);
- dialog.set_value("subject", frm.doc.subject);
dialog.show();
}
})
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 bd65b0c..394a5c7 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -20,11 +20,10 @@
"items_section",
"items",
"supplier_response_section",
- "salutation",
- "subject",
- "col_break_email_1",
"email_template",
"preview",
+ "col_break_email_1",
+ "html_llwp",
"sec_break_email_2",
"message_for_supplier",
"terms_section_break",
@@ -237,23 +236,6 @@
"read_only": 1
},
{
- "fetch_from": "email_template.subject",
- "fetch_if_empty": 1,
- "fieldname": "subject",
- "fieldtype": "Data",
- "label": "Subject",
- "print_hide": 1
- },
- {
- "description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
- "fieldname": "salutation",
- "fieldtype": "Link",
- "label": "Salutation",
- "no_copy": 1,
- "options": "Salutation",
- "print_hide": 1
- },
- {
"fieldname": "col_break_email_1",
"fieldtype": "Column Break"
},
@@ -285,13 +267,19 @@
"fieldname": "named_place",
"fieldtype": "Data",
"label": "Named Place"
+ },
+ {
+ "fieldname": "html_llwp",
+ "fieldtype": "HTML",
+ "options": "<p>In your <b>Email Template</b>, you can use the following special variables:\n</p>\n<ul>\n <li>\n <code>{{ update_password_link }}</code>: A link where your supplier can set a new password to log into your portal.\n </li>\n <li>\n <code>{{ portal_link }}</code>: A link to this RFQ in your supplier portal.\n </li>\n <li>\n <code>{{ supplier_name }}</code>: The company name of your supplier.\n </li>\n <li>\n <code>{{ contact.salutation }} {{ contact.last_name }}</code>: The contact person of your supplier.\n </li><li>\n <code>{{ user_fullname }}</code>: Your full name.\n </li>\n </ul>\n<p></p>\n<p>Apart from these, you can access all values in this RFQ, like <code>{{ message_for_supplier }}</code> or <code>{{ terms }}</code>.</p>",
+ "read_only": 1
}
],
"icon": "fa fa-shopping-cart",
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2023-01-31 23:22:06.684694",
+ "modified": "2023-07-27 14:01:14.534594",
"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 4590f8c..1c17233 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -179,35 +179,28 @@
if full_name == "Guest":
full_name = "Administrator"
- # send document dict and some important data from suppliers row
- # to render message_for_supplier from any template
doc_args = self.as_dict()
- doc_args.update({"supplier": data.get("supplier"), "supplier_name": data.get("supplier_name")})
- # Get Contact Full Name
- supplier_name = None
if data.get("contact"):
- contact_name = frappe.db.get_value(
- "Contact", data.get("contact"), ["first_name", "middle_name", "last_name"]
- )
- supplier_name = (" ").join(x for x in contact_name if x) # remove any blank values
+ contact = frappe.get_doc("Contact", data.get("contact"))
+ doc_args["contact"] = contact.as_dict()
- args = {
- "update_password_link": update_password_link,
- "message": frappe.render_template(self.message_for_supplier, doc_args),
- "rfq_link": rfq_link,
- "user_fullname": full_name,
- "supplier_name": supplier_name or data.get("supplier_name"),
- "supplier_salutation": self.salutation or "Dear Mx.",
- }
-
- subject = self.subject or _("Request for Quotation")
- template = "templates/emails/request_for_quotation.html"
+ doc_args.update(
+ {
+ "supplier": data.get("supplier"),
+ "supplier_name": data.get("supplier_name"),
+ "update_password_link": f'<a href="{update_password_link}" class="btn btn-default btn-xs" target="_blank">{_("Set Password")}</a>',
+ "portal_link": f'<a href="{rfq_link}" class="btn btn-default btn-sm" target="_blank"> {_("Submit your Quotation")} </a>',
+ "user_fullname": full_name,
+ }
+ )
+ email_template = frappe.get_doc("Email Template", self.email_template)
+ message = frappe.render_template(email_template.response_, doc_args)
+ subject = frappe.render_template(email_template.subject, doc_args)
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
+ return {"message": message, "subject": subject}
attachments = self.get_attachments()
diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html
deleted file mode 100644
index 5b073e6..0000000
--- a/erpnext/templates/emails/request_for_quotation.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<h4>{{_("Request for Quotation")}}</h4>
-<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 button")}}:</p>
-<br>
-<a
- href="{{ rfq_link }}"
- class="btn btn-default btn-sm"
- target="_blank">
- {{ _("Submit your Quotation") }}
-</a>
-<br>
-<br>
-{% if update_password_link %}
-<br>
-<p>{{_("Please click on the following button to set your new password")}}:</p>
-<a
- href="{{ update_password_link }}"
- class="btn btn-default btn-xs"
- target="_blank">
- {{_("Set Password") }}
-</a>
-<br>
-<br>
-{% endif %}
-<p>
- {{_("Regards")}},<br>
- {{ user_fullname }}
-</p>