def irs_1099_print(filters): if not filters: frappe._dict({ "company": frappe.db.get_default("Company"), "fiscal_year": frappe.db.get_default("Fiscal Year") }) else: filters = frappe._dict(json.loads(filters)) fiscal_year_doc = get_fiscal_year(fiscal_year=filters.fiscal_year, as_dict=True) fiscal_year = cstr(fiscal_year_doc.year_start_date.year) company_address = get_payer_address_html(filters.company) company_tin = frappe.db.get_value("Company", filters.company, "tax_id") columns, data = execute(filters) template = frappe.get_doc("Print Format", "IRS 1099 Form").html output = PdfFileWriter() for row in data: row["fiscal_year"] = fiscal_year row["company"] = filters.company row["company_tin"] = company_tin row["payer_street_address"] = company_address row["recipient_street_address"], row["recipient_city_state"] = get_street_address_html( "Supplier", row.supplier) row["payments"] = fmt_money(row["payments"], precision=0, currency="USD") pdf = get_pdf(render_template(template, row), output=output if output else None) frappe.local.response.filename = f"{filters.fiscal_year} {filters.company} IRS 1099 Forms{IRS_1099_FORMS_FILE_EXTENSION}" frappe.local.response.filecontent = read_multi_pdf(output) frappe.local.response.type = "download"
def print_multiple_label_pdf(printer_name, contents): label_printer = frappe.get_doc("Label Printer", printer_name) if isinstance(contents, six.string_types): contents = json.loads(contents) # Create a multi-page PDF with several labels for each batch (based on 'verpackungseinheit') output = PdfFileWriter() for content in contents: item = frappe.get_doc("Item", content[0]) if item.verpackungseinheit > 0: loops = int(content[1] / item.verpackungseinheit) loop_qty = item.verpackungseinheit item_code = content[0] if item.artikelcode_kunde: item_code = item.artikelcode_kunde # One label per full packing size for i in range(loops): create_single_label_pdf(label_printer, item, content[2], loop_qty, output) # Optional extra label for remaining quantity if (loops * loop_qty) < content[1]: create_single_label_pdf(label_printer, item, content[2], (content[1] - (loops * loop_qty)), output) # print the merged pdf filedata = read_multi_pdf(output) direct_print_pdf(filedata, printer_name)
def email_all_internal_invoices(invoice_list=None, format="Sales Invoice SNS"): invoice_list = json.loads(invoice_list) if invoice_list else [] if not invoice_list: return data = frappe.db.sql( """select company, monthname(posting_date) month, customer, group_concat(name) invoices from `tabSales Invoice` where customer_group = 'Internal' and name in ({}) group by company, monthname(posting_date), customer order by company, monthname(posting_date), customer """.format(",".join(["'%s'" % d for d in invoice_list])), as_dict=1) output = PdfFileWriter() from frappe.utils.print_format import read_multi_pdf from frappe.utils.pdf import get_pdf for d in data: invoices = ",".join(["'%s'" % m for m in d.invoices.split(",")]) html = get_invoice_summary(invoices) output = get_pdf(html, output=output) for i in d.invoices.split(","): output = frappe.get_print( "Sales Invoice", i, format, as_pdf=True, output=output) send_customer_emails(d.company, d.customer, d.month, invoices, read_multi_pdf(output))
def get_invoice_merged(invoices, print_format="Sales Invoice SNS"): invoices = ['SINV-SNS-190227-1', 'SINV-SNS-190227-3'] # print_format = frappe.db.get_single_value("Delivery Settings", "dispatch_attachment") attachments = [] from PyPDF2 import PdfFileWriter, PdfFileReader output = PdfFileWriter() for invoice in invoices: output = frappe.get_print("Sales Invoice", invoice, print_format, as_pdf=True, output=output) from frappe.utils.print_format import read_multi_pdf return [{ "fname": "Internal Voucher.pdf", "fcontent": read_multi_pdf(output) }]