From c308bd53097679c0d5dab16af2786861b1dedf2f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:11:37 +0530 Subject: [PATCH] feat(RFQ): make email message fully configurable (backport #36353) (#36531) * feat(RFQ): make email message fully configurable (#36353) feat: make RFQ message fully configurable (cherry picked from commit 21080afd92d42c12d302f8f1499c0697e571790e) * fix(RFQ): hide description in print and report --------- Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../request_for_quotation.js | 16 ++++---- .../request_for_quotation.json | 32 ++++++---------- .../request_for_quotation.py | 37 ++++++++----------- .../emails/request_for_quotation.html | 29 --------------- 4 files changed, 35 insertions(+), 79 deletions(-) delete mode 100644 erpnext/templates/emails/request_for_quotation.html 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 2f0b7862a82..30abad528bf 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -245,19 +245,21 @@ frappe.ui.form.on("Request for Quotation",{ ] }); - 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(`

This is a preview of the email to be sent. A PDF of the document will automatically be attached with the email.

`); - 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 c16abb2f41b..fbfc1ac1693 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", "send_attached_files", "sec_break_email_2", "message_for_supplier", @@ -237,23 +236,6 @@ "print_hide": 1, "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" @@ -287,6 +269,14 @@ "fieldtype": "Data", "label": "Named Place" }, + { + "fieldname": "html_llwp", + "fieldtype": "HTML", + "options": "

In your Email Template, you can use the following special variables:\n

\n\n

\n

Apart from these, you can access all values in this RFQ, like {{ message_for_supplier }} or {{ terms }}.

", + "print_hide": 1, + "read_only": 1, + "report_hide": 1 + }, { "default": "1", "description": "If enabled, all files attached to this document will be attached to each email", @@ -299,7 +289,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-07-27 16:41:48.468873", + "modified": "2023-08-08 16:30:10.870429", "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 63e393aecd6..e9385777e5d 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -182,35 +182,28 @@ class RequestforQuotation(BuyingController): 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'{_("Set Password")}', + "portal_link": f' {_("Submit your Quotation")} ', + "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 = None if self.send_attached_files: diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html deleted file mode 100644 index 5b073e604ff..00000000000 --- a/erpnext/templates/emails/request_for_quotation.html +++ /dev/null @@ -1,29 +0,0 @@ -

{{_("Request for Quotation")}}

-

{{ supplier_salutation if supplier_salutation else ''}} {{ supplier_name }},

-

{{ message }}

-

{{_("The Request for Quotation can be accessed by clicking on the following button")}}:

-
- - {{ _("Submit your Quotation") }} - -
-
-{% if update_password_link %} -
-

{{_("Please click on the following button to set your new password")}}:

- - {{_("Set Password") }} - -
-
-{% endif %} -

- {{_("Regards")}},
- {{ user_fullname }} -