mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
fix: Reuse function to render email preview
- Reused `supplier_rfq_mail` to render preview - Print hid Salutation and Subject - Completely dynamic greeting
This commit is contained in:
@@ -213,7 +213,8 @@ frappe.ui.form.on("Request for Quotation",{
|
|||||||
label: __('Subject'),
|
label: __('Subject'),
|
||||||
fieldtype: 'Data',
|
fieldtype: 'Data',
|
||||||
fieldname: 'subject',
|
fieldname: 'subject',
|
||||||
read_only: 1
|
read_only: 1,
|
||||||
|
depends_on: 'subject'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldtype: 'Section Break',
|
fieldtype: 'Section Break',
|
||||||
@@ -229,12 +230,8 @@ frappe.ui.form.on("Request for Quotation",{
|
|||||||
});
|
});
|
||||||
|
|
||||||
dialog.fields_dict['supplier'].df.onchange = () => {
|
dialog.fields_dict['supplier'].df.onchange = () => {
|
||||||
var args = {
|
var supplier = dialog.get_value('supplier');
|
||||||
'supplier' : dialog.get_value('supplier'),
|
frm.call('get_supplier_email_preview', {supplier: supplier}).then(result => {
|
||||||
'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.empty();
|
||||||
dialog.fields_dict.email_preview.$wrapper.append(result.message);
|
dialog.fields_dict.email_preview.$wrapper.append(result.message);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -245,14 +245,17 @@
|
|||||||
"fetch_if_empty": 1,
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "subject",
|
"fieldname": "subject",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Subject"
|
"label": "Subject",
|
||||||
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
|
"description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
|
||||||
"fieldname": "salutation",
|
"fieldname": "salutation",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Salutation",
|
"label": "Salutation",
|
||||||
"options": "Salutation"
|
"no_copy": 1,
|
||||||
|
"options": "Salutation",
|
||||||
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "col_break_email_1",
|
"fieldname": "col_break_email_1",
|
||||||
@@ -273,7 +276,7 @@
|
|||||||
"icon": "fa fa-shopping-cart",
|
"icon": "fa fa-shopping-cart",
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-09-28 14:25:31.357817",
|
"modified": "2020-09-28 17:37:10.313350",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Request for Quotation",
|
"name": "Request for Quotation",
|
||||||
|
|||||||
@@ -62,29 +62,15 @@ class RequestforQuotation(BuyingController):
|
|||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
frappe.db.set(self, 'status', 'Cancelled')
|
frappe.db.set(self, 'status', 'Cancelled')
|
||||||
|
|
||||||
def get_supplier_email_preview(self, args):
|
def get_supplier_email_preview(self, supplier):
|
||||||
rfq_suppliers = list(filter(lambda row: row.supplier == args.get('supplier'), self.suppliers))
|
# Returns formatted email preview as string
|
||||||
rfq_supplier = rfq_suppliers[0].as_dict()
|
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())
|
update_password_link = self.update_supplier_contact(rfq_supplier, self.get_link())
|
||||||
|
|
||||||
full_name = get_user_fullname(frappe.session['user'])
|
message = self.supplier_rfq_mail(rfq_supplier, update_password_link, self.get_link(), True)
|
||||||
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
|
return message
|
||||||
|
|
||||||
def send_to_supplier(self):
|
def send_to_supplier(self):
|
||||||
@@ -154,7 +140,7 @@ class RequestforQuotation(BuyingController):
|
|||||||
|
|
||||||
return user, update_password_link
|
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'])
|
full_name = get_user_fullname(frappe.session['user'])
|
||||||
if full_name == "Guest":
|
if full_name == "Guest":
|
||||||
full_name = "Administrator"
|
full_name = "Administrator"
|
||||||
@@ -163,13 +149,19 @@ class RequestforQuotation(BuyingController):
|
|||||||
'update_password_link': update_password_link,
|
'update_password_link': update_password_link,
|
||||||
'message': frappe.render_template(self.message_for_supplier, data.as_dict()),
|
'message': frappe.render_template(self.message_for_supplier, data.as_dict()),
|
||||||
'rfq_link': rfq_link,
|
'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"
|
template = "templates/emails/request_for_quotation.html"
|
||||||
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
|
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
|
||||||
message = frappe.get_template(template).render(args)
|
message = frappe.get_template(template).render(args)
|
||||||
|
|
||||||
|
if preview:
|
||||||
|
return message
|
||||||
|
|
||||||
attachments = self.get_attachments()
|
attachments = self.get_attachments()
|
||||||
|
|
||||||
self.send_email(data, sender, subject, message, attachments)
|
self.send_email(data, sender, subject, message, attachments)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<h4>{{_("Request for Quotation")}}</h4>
|
<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>{{ 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>
|
<p>
|
||||||
<button style="border: 1px solid #15c; padding: 6px; border-radius: 5px; background-color: white;">
|
<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>
|
</button>
|
||||||
</p><br>
|
</p><br>
|
||||||
|
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
{% if update_password_link %}
|
{% if update_password_link %}
|
||||||
<div>
|
<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>
|
<p>
|
||||||
<button style="border: 1px solid #15c; padding: 4px; border-radius: 5px; background-color: white;">
|
<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>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user