Exemplo n.º 1
0
def export_query_report():
    """export from query reports"""
    from frappe.desk.query_report import get_columns_dict

    data = frappe._dict(frappe.local.form_dict)

    del data["cmd"]
    if "csrf_token" in data:
        del data["csrf_token"]

    if isinstance(data.get("filters"), six.string_types):
        filters = json.loads(data["filters"])
    if isinstance(data.get("report_name"), six.string_types):
        report_name = data["report_name"]
    if isinstance(data.get("file_format_type"), six.string_types):
        file_format_type = data["file_format_type"]
    if isinstance(data.get("visible_idx"), six.string_types):
        visible_idx = json.loads(data.get("visible_idx"))
    else:
        visible_idx = None

    if file_format_type == "Excel":

        data = query_report_run(report_name, filters)
        data = frappe._dict(data)
        columns = get_columns_dict(data.columns)

        result = [[]]

        # add column headings
        for idx in range(len(data.columns)):
            result[0].append(columns[idx]["label"])

        # build table from dict
        if isinstance(data.result[0], dict):
            for i, row in enumerate(data.result):
                # only rows which are visible in the report
                if row and (i in visible_idx):
                    row_list = []
                    for idx in range(len(data.columns)):
                        row_list.append(row.get(columns[idx]["fieldname"], ""))
                    result.append(row_list)
                elif not row:
                    result.append([])
        else:
            result = result + [
                d for i, d in enumerate(data.result) if (i in visible_idx)
            ]

        from frappe.utils.xlsxutils import make_xlsx
        xlsx_file = make_xlsx(result, "Query Report")

        frappe.response['filename'] = report_name + '.xlsx'
        frappe.response['filecontent'] = xlsx_file.getvalue()
        frappe.response['type'] = 'binary'
Exemplo n.º 2
0
    def wrapper(data):
        report_name = data.get('report_name')
        include_indentation = data.get('include_indentation')

        filters = json.loads(data.get('filters'))
        visible_idx = json.loads(data.get('visible_idx'))

        report_data = frappe._dict(run(report_name, filters))
        columns = get_columns_dict(report_data.columns)

        xlsx_data = build_xlsx_data(columns, report_data, visible_idx,
                                    include_indentation)

        row_length = len(xlsx_data[0])

        build = partial(build_xlsx, report_name, xlsx_data)

        return func(build, filters, row_length)
def export_my_query(filters, ws=None, wb=None):

    data = frappe._dict(frappe.local.form_dict)
    del data["cmd"]
    if "csrf_token" in data:
        del data["csrf_token"]

    if isinstance(data.get("report_name"), string_types):
        report_name = data["report_name"]

    data = run("Employee Yearly Summary", filters)
    data = frappe._dict(data)
    columns = get_columns_dict(data.columns)

    result = [[]]

    # add column headings
    for idx in range(len(data.columns)):
        result[0].append(columns[idx]["label"])

    # build table from dict
    if isinstance(data.result[0], dict):
        for i, row in enumerate(data.result):
            # only rows which are visible in the report
            if row:
                row_list = []
                for idx in range(len(data.columns)):
                    row_list.append(row.get(columns[idx]["fieldname"], ""))
                result.append(row_list)
            elif not row:
                result.append([])
    else:
        result = result + [d for i, d in enumerate(data.result)]

    from frappe.utils.xlsxutils import make_xlsx
    if ws is None:
        ws = "Query Report"
    xlsx_file = make_xlsx(result, ws, wb)

    frappe.response['filename'] = report_name + '.xlsx'
    frappe.response['filecontent'] = xlsx_file.getvalue()
    frappe.response['type'] = 'binary'
Exemplo n.º 4
0
def export_query():
    """export from query reports"""
    data = frappe._dict(frappe.local.form_dict)

    del data["cmd"]
    if "csrf_token" in data:
        del data["csrf_token"]

    if isinstance(data.get("filters"), string_types):
        filters = json.loads(data["filters"])
    if isinstance(data.get("report_name"), string_types):
        report_name = data["report_name"]
        frappe.permissions.can_export(frappe.get_cached_value(
            'Report', report_name, 'ref_doctype'),
                                      raise_exception=True)
    if isinstance(data.get("file_format_type"), string_types):
        file_format_type = data["file_format_type"]

    if isinstance(data.get("visible_idx"), string_types):
        visible_idx = json.loads(data.get("visible_idx"))
    else:
        visible_idx = None

    # add filter this customer
    party = get_party()
    filters["customer"] = party.name or ""

    if file_format_type == "Excel":
        data = run(report_name, filters)
        data = frappe._dict(data)
        columns = get_columns_dict(data.columns)

        from frappe.utils.xlsxutils import make_xlsx
        xlsx_data = build_xlsx_data(columns, data)

        xlsx_file = make_xlsx(xlsx_data, "Query Report")

        frappe.response['filename'] = report_name + '.xlsx'
        frappe.response['filecontent'] = xlsx_file.getvalue()
        frappe.response['type'] = 'binary'
Exemplo n.º 5
0
def remove_header_meta(columns):
    column_list = []
    columns_header = get_columns_dict(columns)
    for idx in range(len(columns)):
        column_list.append(columns_header[idx]['label'])
    return column_list