def get_prepared_report_result(report, filters, dn="", user=None): latest_report_data = {} # Only look for completed prepared reports with given filters. doc_list = frappe.get_all("Prepared Report", filters={"status": "Completed", "report_name": report.name, "filters": json.dumps(filters), "owner": user}) doc = None if len(doc_list): if dn: # Get specified dn doc = frappe.get_doc("Prepared Report", dn) else: # Get latest doc = frappe.get_doc("Prepared Report", doc_list[0]) # Prepared Report data is stored in a GZip compressed JSON file attached_file_name = frappe.db.get_value("File", {"attached_to_doctype": doc.doctype, "attached_to_name":doc.name}, "name") compressed_content = get_file(attached_file_name)[1] uncompressed_content = gzip_decompress(compressed_content) data = json.loads(uncompressed_content) if data: latest_report_data = { "columns": json.loads(doc.columns) if doc.columns else data[0], "result": data } latest_report_data.update({ "prepared_report": True, "doc": doc }) return latest_report_data
def get_prepared_report_result(report, filters, dn="", user=None): latest_report_data = {} doc = None if dn: # Get specified dn doc = frappe.get_doc("Prepared Report", dn) else: # Only look for completed prepared reports with given filters. doc_list = frappe.get_all("Prepared Report", filters={ "status": "Completed", "filters": json.dumps(filters), "owner": user, "report_name": report.get('custom_report') or report.get('report_name') }, order_by='creation desc') if doc_list: # Get latest doc = frappe.get_doc("Prepared Report", doc_list[0]) if doc: try: # Prepared Report data is stored in a GZip compressed JSON file attached_file_name = frappe.db.get_value( "File", { "attached_to_doctype": doc.doctype, "attached_to_name": doc.name }, "name") attached_file = frappe.get_doc('File', attached_file_name) compressed_content = attached_file.get_content() uncompressed_content = gzip_decompress(compressed_content) data = json.loads(uncompressed_content) if data: columns = json.loads(doc.columns) if doc.columns else data[0] for column in columns: if isinstance(column, dict): column["label"] = _(column["label"]) latest_report_data = {"columns": columns, "result": data} except Exception: frappe.log_error(frappe.get_traceback()) frappe.delete_doc("Prepared Report", doc.name) frappe.db.commit() doc = None latest_report_data.update({"prepared_report": True, "doc": doc}) return latest_report_data
def get_prepared_report_result(report, filters, dn="", user=None): latest_report_data = {} doc = None if dn: # Get specified dn doc = frappe.get_doc("Prepared Report", dn) else: # Only look for completed prepared reports with given filters. doc_list = frappe.get_all("Prepared Report", filters={ "status": "Completed", "filters": json.dumps(filters), "owner": user }) if doc_list: # Get latest doc = frappe.get_doc("Prepared Report", doc_list[0]) if doc: try: # Prepared Report data is stored in a GZip compressed JSON file attached_file_name = frappe.db.get_value( "File", { "attached_to_doctype": doc.doctype, "attached_to_name": doc.name }, "name") attached_file = frappe.get_doc('File', attached_file_name) compressed_content = attached_file.get_content() uncompressed_content = gzip_decompress(compressed_content) data = json.loads(uncompressed_content) if data: latest_report_data = { "columns": json.loads(doc.columns) if doc.columns else data[0], "result": data } except Exception: frappe.delete_doc("Prepared Report", doc.name) frappe.db.commit() doc = None latest_report_data.update({"prepared_report": True, "doc": doc}) return latest_report_data
def download_attachment(dn): attachment = get_attachments("Prepared Report", dn)[0] frappe.local.response.filename = attachment.file_name[:-2] frappe.local.response.filecontent = gzip_decompress(get_file(attachment.name)[1]) frappe.local.response.type = "binary"
def download_attachment(dn): attachment = get_attachments("Prepared Report", dn)[0] frappe.local.response.filename = attachment.file_name[:-2] attached_file = frappe.get_doc("File", attachment.name) frappe.local.response.filecontent = gzip_decompress(attached_file.get_content()) frappe.local.response.type = "binary"