From fe2d5b587f1ab2d379d2785fca8ef49d41de93c7 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Thu, 2 May 2024 15:28:39 +0530 Subject: [PATCH 1/2] chore: fix typo in patch_utils when patch was modified to also run on print_designer_print_formats field. i accidentally messed up lines and spacing, this commit fixes it. went unnoticed because the patch was already applied locally in the first run. --- print_designer/patches/patch_utils.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/print_designer/patches/patch_utils.py b/print_designer/patches/patch_utils.py index 4f8e94e..1ad872b 100644 --- a/print_designer/patches/patch_utils.py +++ b/print_designer/patches/patch_utils.py @@ -106,17 +106,20 @@ def patch_formats( ], as_list=1, ) - if update_print_json: - for pf in print_formats: - # print_designer_print_format was introduced in schema version 1.1.0 so running this on older version is not required - if not is_older_schema(settings=frappe.json.loads(pf[6] or "{}"), current_version="1.1.0"): - print_json = frappe.json.loads(pf[5] or "{}") - if print_json.get("header", None): - print_json["header"] = patch_elements(print_json["header"], callbacks, types) - if print_json.get("body", None): - print_json["body"] = patch_elements(print_json["body"], callbacks, types) - if print_json.get("footer", None): - print_json["footer"] = patch_elements(print_json["footer"], callbacks, types) + for pf in print_formats: + print_json = pf[5] or "{}" + # print_designer_print_format was introduced in schema version 1.1.0 so running this on older version is not required + if update_print_json and not is_older_schema( + settings=frappe.json.loads(pf[6] or "{}"), current_version="1.1.0" + ): + print_json = frappe.json.loads(print_json) + if print_json.get("header", None): + print_json["header"] = patch_elements(print_json["header"], callbacks, types) + if print_json.get("body", None): + print_json["body"] = patch_elements(print_json["body"], callbacks, types) + if print_json.get("footer", None): + print_json["footer"] = patch_elements(print_json["footer"], callbacks, types) + print_json = frappe.json.dumps(print_json) updated_doc = frappe.get_doc("Print Format", pf[0]).update( { @@ -132,7 +135,7 @@ def patch_formats( "print_designer_footer": frappe.json.dumps( patch_elements(frappe.json.loads(pf[4] or "[]"), callbacks, types) ), - "print_designer_print_format": frappe.json.dumps(print_json), + "print_designer_print_format": print_json, } ) if save: From badbb0567ab941f3883c03afe99b819b16c8f526 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 14 May 2024 09:37:58 +0530 Subject: [PATCH 2/2] fix(minor): call the framework pdf_body_html func instead of rendering template directly call the framework pdf_body_html function to render the html. --- print_designer/pdf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print_designer/pdf.py b/print_designer/pdf.py index 297b508..f404210 100644 --- a/print_designer/pdf.py +++ b/print_designer/pdf.py @@ -6,6 +6,7 @@ from frappe.monitor import add_data_to_monitor from frappe.utils.error import log_error from frappe.utils.jinja_globals import is_rtl +from frappe.utils.pdf import pdf_body_html as fw_pdf_body_html def pdf_header_footer_html(soup, head, content, styles, html_id, css): @@ -82,8 +83,7 @@ def pdf_body_html(print_format, jenv, args, template): return f"

Something went wrong while rendering the print format.
If you don't know what just happened, and wish to file a ticket or issue on Github
Please copy the error from Error Log {error.name} or ask Administrator.

Error rendering print format: {error.reference_name}

{error.method}

{html.escape(error.error)}
" else: return f"

Something went wrong while rendering the print format.
If you don't know what just happened, and wish to file a ticket or issue on Github
Please copy the error from Error Log {error.name} or ask Administrator.

" - - return template.render(args, filters={"len": len}) + return fw_pdf_body_html(template, args) def is_older_schema(settings, current_version):