From a2ef745f18775342190f9d9aaeafcf3731aca236 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 9 Jul 2014 11:29:49 +0530 Subject: [PATCH] Option in Outgoing Email Settings to Send Attached Document Print as PDF --- frappe/core/doctype/communication/communication.py | 14 ++++++++++---- .../outgoing_email_settings.json | 8 +++++++- frappe/patches.txt | 1 + frappe/patches/v4_1/enable_print_as_pdf.py | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 frappe/patches/v4_1/enable_print_as_pdf.py diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 63bfcebca4..5f204d887f 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -129,10 +129,16 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s if print_html: print_html = scrub_urls(print_html) - try: - mail.add_pdf_attachment(name.replace(' ','').replace('/','-') + '.pdf', print_html) - except Exception: - frappe.msgprint(_("Error generating PDF, attachment sent as HTML")) + send_print_as_pdf = cint(frappe.db.get_value("Outgoing Email Settings", "Outgoing Email Settings", "send_print_as_pdf")) + + if send_print_as_pdf: + try: + mail.add_pdf_attachment(name.replace(' ','').replace('/','-') + '.pdf', print_html) + except Exception: + frappe.msgprint(_("Error generating PDF, attachment sent as HTML")) + send_print_as_pdf = 0 + + if not send_print_as_pdf: mail.add_attachment(name.replace(' ','').replace('/','-') + '.html', print_html, 'text/html') diff --git a/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json b/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json index 4d3fcb7f62..71630fcafc 100644 --- a/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json +++ b/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json @@ -74,6 +74,12 @@ "label": "Auto Email Id", "permlevel": 0 }, + { + "fieldname": "send_print_as_pdf", + "fieldtype": "Check", + "label": "Send Attached Document Print as PDF", + "permlevel": 0 + }, { "fieldname": "section_break_10", "fieldtype": "Section Break", @@ -92,7 +98,7 @@ "idx": 1, "in_create": 1, "issingle": 1, - "modified": "2014-07-07 11:42:10.128767", + "modified": "2014-07-09 01:47:56.027654", "modified_by": "Administrator", "module": "Core", "name": "Outgoing Email Settings", diff --git a/frappe/patches.txt b/frappe/patches.txt index d34c5bfb7b..50c5b4e1c3 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -46,3 +46,4 @@ execute:frappe.reload_doc('website', 'doctype', 'website_route') #2014-06-17 execute:frappe.db.sql("""update `tabProperty Setter` set property_type='Text' where property in ('options', 'default')""") #2014-06-20 frappe.patches.v4_1.enable_outgoing_email_settings execute:frappe.db.sql("""update `tabSingles` set `value`=`doctype` where `field`='name'""") #2014-07-04 +frappe.patches.v4_1.enable_print_as_pdf diff --git a/frappe/patches/v4_1/enable_print_as_pdf.py b/frappe/patches/v4_1/enable_print_as_pdf.py new file mode 100644 index 0000000000..d4d152c569 --- /dev/null +++ b/frappe/patches/v4_1/enable_print_as_pdf.py @@ -0,0 +1,14 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc("core", "doctype", "outgoing_email_settings") + try: + import pdfkit + except ImportError: + pass + else: + frappe.db.set_value("Outgoing Email Settings", "Outgoing Email Settings", "send_print_as_pdf", 1)