Esempio n. 1
0
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0):
    html = dataent.get_print(doctype,
                             name,
                             format,
                             doc=doc,
                             no_letterhead=no_letterhead)
    dataent.local.response.filename = "{name}.pdf".format(
        name=name.replace(" ", "-").replace("/", "-"))
    dataent.local.response.filecontent = get_pdf(html)
    dataent.local.response.type = "pdf"
Esempio n. 2
0
def make_salary_slip(source_name,
                     target_doc=None,
                     employee=None,
                     as_print=False,
                     print_format=None,
                     for_preview=0):
    def postprocess(source, target):
        if employee:
            employee_details = dataent.db.get_value(
                "Employee",
                employee,
                ["employee_name", "branch", "designation", "department"],
                as_dict=1)
            target.employee = employee
            target.employee_name = employee_details.employee_name
            target.branch = employee_details.branch
            target.designation = employee_details.designation
            target.department = employee_details.department
        target.run_method('process_salary_structure', for_preview=for_preview)

    doc = get_mapped_doc("Salary Structure",
                         source_name, {
                             "Salary Structure": {
                                 "doctype": "Salary Slip",
                                 "field_map": {
                                     "total_earning": "gross_pay",
                                     "name": "salary_structure"
                                 }
                             }
                         },
                         target_doc,
                         postprocess,
                         ignore_child_tables=True)

    if cint(as_print):
        doc.name = 'Preview for {0}'.format(employee)
        return dataent.get_print(doc.doctype,
                                 doc.name,
                                 doc=doc,
                                 print_format=print_format)
    else:
        return doc
Esempio n. 3
0
def print_by_server(doctype,
                    name,
                    print_format=None,
                    doc=None,
                    no_letterhead=0):
    print_settings = dataent.get_doc("Print Settings")
    try:
        import cups
    except ImportError:
        dataent.throw(_("You need to install pycups to use this feature!"))
        return
    try:
        cups.setServer(print_settings.server_ip)
        cups.setPort(print_settings.port)
        conn = cups.Connection()
        output = PdfFileWriter()
        output = dataent.get_print(doctype,
                                   name,
                                   print_format,
                                   doc=doc,
                                   no_letterhead=no_letterhead,
                                   as_pdf=True,
                                   output=output)
        file = os.path.join(
            "/", "tmp", "dataent-pdf-{0}.pdf".format(dataent.generate_hash()))
        output.write(open(file, "wb"))
        conn.printFile(print_settings.printer_name, file, name, {})
    except IOError as e:
        if ("ContentNotFoundError" in e.message
                or "ContentOperationNotPermittedError" in e.message
                or "UnknownContentError" in e.message
                or "RemoteHostClosedError" in e.message):
            dataent.throw(_("PDF generation failed"))
    except cups.IPPError:
        dataent.throw(_("Printing failed"))
    finally:
        cleanup(file, {})
Esempio n. 4
0
	def test_print_user(self, style=None):
		print_html = dataent.get_print("User", "Administrator", style=style)
		self.assertTrue("<label>First Name</label>" in print_html)
		self.assertTrue(re.findall('<div class="col-xs-7[^"]*">[\s]*administrator[\s]*</div>', print_html))
		return print_html
Esempio n. 5
0
def download_multi_pdf(doctype, name, format=None):
    """
	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
    output = PdfFileWriter()

    if not isinstance(doctype, dict):
        result = json.loads(name)

        # Concatenating pdf files
        for i, ss in enumerate(result):
            output = dataent.get_print(doctype,
                                       ss,
                                       format,
                                       as_pdf=True,
                                       output=output)
        dataent.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 = dataent.get_print(doctype_name,
                                               doc_name,
                                               format,
                                               as_pdf=True,
                                               output=output)
                except Exception:
                    dataent.log_error(
                        "Permission Error on doc {} of doctype {}".format(
                            doc_name, doctype_name))
        dataent.local.response.filename = "{}.pdf".format(name)

    dataent.local.response.filecontent = read_multi_pdf(output)
    dataent.local.response.type = "download"