Skip to content

Commit

Permalink
chore: Merge branch 'develop' into zIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
maharshivpatel committed May 16, 2024
2 parents d712abd + 16b30c2 commit 291be9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions print_designer/patches/patch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions print_designer/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -82,8 +83,7 @@ def pdf_body_html(print_format, jenv, args, template):
return f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.<hr /><h3>Error rendering print format: {error.reference_name}</h3><h4>{error.method}</h4><pre>{html.escape(error.error)}</pre>"
else:
return f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.</h1>"

return template.render(args, filters={"len": len})
return fw_pdf_body_html(template, args)


def is_older_schema(settings, current_version):
Expand Down

0 comments on commit 291be9c

Please sign in to comment.