[fix] frappe.attach_print() - encode html if pdf printing is disabled and set file extn accordingly
This commit is contained in:
parent
3eb9e1c156
commit
5ce09c4e0c
1 changed files with 18 additions and 6 deletions
|
|
@ -641,6 +641,8 @@ def format_value(value, df, doc=None, currency=None):
|
|||
|
||||
def get_print_format(doctype, name, print_format=None, style=None, as_pdf=False):
|
||||
from frappe.website.render import build_page
|
||||
from frappe.utils.pdf import get_pdf
|
||||
|
||||
local.form_dict.doctype = doctype
|
||||
local.form_dict.name = name
|
||||
local.form_dict.format = print_format
|
||||
|
|
@ -649,15 +651,25 @@ def get_print_format(doctype, name, print_format=None, style=None, as_pdf=False)
|
|||
html = build_page("print")
|
||||
|
||||
if as_pdf:
|
||||
print_settings = db.get_singles_dict("Print Settings")
|
||||
if int(print_settings.send_print_as_pdf or 0):
|
||||
from utils.pdf import get_pdf
|
||||
return get_pdf(html, {"page-size": print_settings.pdf_page_size})
|
||||
else:
|
||||
return html
|
||||
return get_pdf(html)
|
||||
else:
|
||||
return html
|
||||
|
||||
def attach_print(doctype, name, file_name):
|
||||
from frappe.utils import scrub_urls
|
||||
|
||||
print_settings = db.get_singles_dict("Print Settings")
|
||||
if int(print_settings.send_print_as_pdf or 0):
|
||||
return {
|
||||
"fname": file_name + ".pdf",
|
||||
"fcontent": get_print_format(doctype, name, as_pdf=True)
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"fname": file_name + ".html",
|
||||
"fcontent": scrub_urls(get_print_format(doctype, name)).encode("utf-8")
|
||||
}
|
||||
|
||||
logging_setup_complete = False
|
||||
def get_logger(module=None):
|
||||
from frappe.setup_logging import setup_logging
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue