Browse Source

[Enhancement] Print doc without get doc, pass self/doc in attach_print(doc=self) method

version-14
Rohit Waghchaure 9 years ago
parent
commit
4c1824ac09
3 changed files with 11 additions and 6 deletions
  1. +5
    -4
      frappe/__init__.py
  2. +1
    -1
      frappe/email/doctype/email_queue/email_queue.js
  3. +5
    -1
      frappe/www/print.py

+ 5
- 4
frappe/__init__.py View File

@@ -1129,7 +1129,7 @@ def format_value(value, df, doc=None, currency=None):
import frappe.utils.formatters
return frappe.utils.formatters.format_value(value, df, doc, currency=currency)

def get_print(doctype, name, print_format=None, style=None, html=None, as_pdf=False):
def get_print(doctype, name, print_format=None, style=None, html=None, as_pdf=False, doc=None):
"""Get Print Format for given document.

:param doctype: DocType of document.
@@ -1144,6 +1144,7 @@ def get_print(doctype, name, print_format=None, style=None, html=None, as_pdf=Fa
local.form_dict.name = name
local.form_dict.format = print_format
local.form_dict.style = style
local.form_dict.doc = doc

if not html:
html = build_page("print")
@@ -1153,7 +1154,7 @@ def get_print(doctype, name, print_format=None, style=None, html=None, as_pdf=Fa
else:
return html

def attach_print(doctype, name, file_name=None, print_format=None, style=None, html=None):
def attach_print(doctype, name, file_name=None, print_format=None, style=None, html=None, doc=None):
from frappe.utils import scrub_urls

if not file_name: file_name = name
@@ -1166,12 +1167,12 @@ def attach_print(doctype, name, file_name=None, print_format=None, style=None, h
if int(print_settings.send_print_as_pdf or 0):
out = {
"fname": file_name + ".pdf",
"fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True)
"fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc)
}
else:
out = {
"fname": file_name + ".html",
"fcontent": scrub_urls(get_print(doctype, name, print_format=print_format, style=style, html=html)).encode("utf-8")
"fcontent": scrub_urls(get_print(doctype, name, print_format=print_format, style=style, html=html, doc=doc)).encode("utf-8")
}

local.flags.ignore_print_permissions = False


+ 1
- 1
frappe/email/doctype/email_queue/email_queue.js View File

@@ -6,7 +6,7 @@ frappe.ui.form.on("Email Queue", {
if (frm.doc.status==="Not Sent") {
frm.add_custom_button("Send Now", function() {
frappe.call({
method: 'frappe.email.doctype.bulk_email.bulk_email.send_now',
method: 'frappe.email.doctype.email_queue.email_queue.send_now',
args: {
name: frm.doc.name
},


+ 5
- 1
frappe/www/print.py View File

@@ -26,7 +26,11 @@ def get_context(context):
<pre>%s</pre>""" % repr(frappe.form_dict)
}

doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
if frappe.form_dict.doc:
doc = frappe.form_dict.doc
else:
doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)

meta = frappe.get_meta(doc.doctype)

print_format = get_print_format_doc(None, meta = meta)


Loading…
Cancel
Save