Skip to content

Commit

Permalink
feat(RFQ): make email message fully configurable (#36353)
Browse files Browse the repository at this point in the history
feat: make RFQ message fully configurable
(cherry picked from commit 21080af)
  • Loading branch information
barredterra authored and mergify[bot] committed Aug 7, 2023
1 parent d76c2c5 commit 89d105c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<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();
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -236,23 +235,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"
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,28 @@ def supplier_rfq_mail(self, data, update_password_link, rfq_link, preview=False)
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

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.",
}
contact = frappe.get_doc("Contact", data.get("contact"))
doc_args["contact"] = contact.as_dict()

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()

Expand Down
29 changes: 0 additions & 29 deletions erpnext/templates/emails/request_for_quotation.html

This file was deleted.

0 comments on commit 89d105c

Please sign in to comment.