I am trying to customize the gl report print format im my custom app
approaches I tried:
1- monkey patching: ingl_print_override/_ init _.py I have added the code below
frappe.utils.print_format.report_to_pdf = gl_print_override.overrides.printing.report_to_pdf
but the downloaded file keeps the original print format
2- Hook: in gl_print_override/hooks.py I have added the code below:
override_whitelisted_methods = {
"frappe.utils.print_format.report_to_pdf": "gl_print_override.overrides.printing.report_to_pdf"
}
I got 403 permission error on frappe.utils.print_format.report_to_pdf
and this is the gl_print_override/overrides/printing.py code :
import frappe
from frappe.utils.pdf import get_pdf
from frappe.utils.print_format import report_to_pdf as _orig_report_to_pdf
@frappe.whitelist()
def report_to_pdf(*args, **kwargs):
report_name = kwargs.get("report_name")
filters = kwargs.get("filters", {})
if report_name == "General Ledger":
context = {"filters": filters, "_": frappe._}
html = frappe.render_template(
"gl_print_override/templates/print_formats/gl_custom.html",
context
)
pdf_bytes = get_pdf(html, options={"orientation": "Landscape"})
if hasattr(frappe.local, "request") and frappe.local.request:
frappe.local.response.filename = "general_ledger.pdf"
frappe.local.response.filecontent = pdf_bytes
frappe.local.response.type = "download"
return
else:
return pdf_bytes
return _orig_report_to_pdf(*args, **kwargs)
type or paste code here
i have also tried @frappe.whitelist(allow_guest=False)
note: when i test in bench console i get the customized file
any help will be appreciated
thanks in advance