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: 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):