Merge pull request #5992 from codingCoffee/print
[feature] print multiple docs from multiple doctypes
This commit is contained in:
commit
c60e976fdc
1 changed files with 54 additions and 7 deletions
|
|
@ -17,17 +17,64 @@ standard_format = "templates/print_formats/standard.html"
|
|||
|
||||
@frappe.whitelist()
|
||||
def download_multi_pdf(doctype, name, format=None):
|
||||
# name can include names of many docs of the same doctype.
|
||||
"""
|
||||
Concatenate multiple docs as PDF .
|
||||
|
||||
Returns a PDF compiled by concatenating multiple documents. The documents
|
||||
can be from a single DocType or multiple DocTypes
|
||||
|
||||
Note: The design may seem a little weird, but it exists exists to
|
||||
ensure backward compatibility. The correct way to use this function is to
|
||||
pass a dict to doctype as described below
|
||||
|
||||
NEW FUNCTIONALITY
|
||||
=================
|
||||
Parameters:
|
||||
doctype (dict):
|
||||
key (string): DocType name
|
||||
value (list): of strings of doc names which need to be concatenated and printed
|
||||
name (string):
|
||||
name of the pdf which is generated
|
||||
format:
|
||||
Print Format to be used
|
||||
|
||||
Returns:
|
||||
PDF: A PDF generated by the concatenation of the mentioned input docs
|
||||
|
||||
OLD FUNCTIONALITY - soon to be deprecated
|
||||
=========================================
|
||||
Parameters:
|
||||
doctype (string):
|
||||
name of the DocType to which the docs belong which need to be printed
|
||||
name (string or list):
|
||||
If string the name of the doc which needs to be printed
|
||||
If list the list of strings of doc names which needs to be printed
|
||||
format:
|
||||
Print Format to be used
|
||||
|
||||
Returns:
|
||||
PDF: A PDF generated by the concatenation of the mentioned input docs
|
||||
"""
|
||||
|
||||
import json
|
||||
result = json.loads(name)
|
||||
|
||||
# Concatenating pdf files
|
||||
output = PdfFileWriter()
|
||||
for i, ss in enumerate(result):
|
||||
output = frappe.get_print(doctype, ss, format, as_pdf = True, output = output)
|
||||
|
||||
frappe.local.response.filename = "{doctype}.pdf".format(doctype=doctype.replace(" ", "-").replace("/", "-"))
|
||||
if not isinstance(doctype, dict):
|
||||
result = json.loads(name)
|
||||
|
||||
# Concatenating pdf files
|
||||
for i, ss in enumerate(result):
|
||||
output = frappe.get_print(doctype, ss, format, as_pdf = True, output = output)
|
||||
frappe.local.response.filename = "{doctype}.pdf".format(doctype=doctype.replace(" ", "-").replace("/", "-"))
|
||||
else:
|
||||
for doctype_name in doctype:
|
||||
for doc_name in doctype[doctype_name]:
|
||||
try:
|
||||
output = frappe.get_print(doctype_name, doc_name, format, as_pdf = True, output = output)
|
||||
except Exception:
|
||||
frappe.log_error("Permission Error on doc {} of doctype {}".format(doc_name, doctype_name))
|
||||
frappe.local.response.filename = "{}.pdf".format(name)
|
||||
|
||||
frappe.local.response.filecontent = read_multi_pdf(output)
|
||||
frappe.local.response.type = "download"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue