diff --git a/print_designer/patches/move_header_footers_to_new_schema.py b/print_designer/patches/move_header_footers_to_new_schema.py index 0eb9e67..143e5a8 100644 --- a/print_designer/patches/move_header_footers_to_new_schema.py +++ b/print_designer/patches/move_header_footers_to_new_schema.py @@ -1,5 +1,7 @@ import frappe +from print_designer.pdf import is_older_schema + def patch_format(): print_formats = frappe.get_all( @@ -57,16 +59,34 @@ def patch_format(): "isDropZone": True, } ] + object_to_save = { + "print_designer_header": frappe.json.dumps(header_data), + "print_designer_body": frappe.json.dumps(bodyPage), + "print_designer_footer": frappe.json.dumps(footer_data), + "print_designer_settings": frappe.json.dumps(settings), + } + if not is_older_schema(settings=settings, current_version="1.1.0"): + pf_print_format = frappe.json.loads(pf.print_designer_print_format) + if "header" in pf_print_format: + pf_print_format["header"] = { + "firstPage": pf_print_format["header"], + "oddPage": pf_print_format["header"], + "evenPage": pf_print_format["header"], + "lastPage": pf_print_format["header"], + } + if "footer" in pf_print_format: + pf_print_format["footer"] = { + "firstPage": pf_print_format["footer"], + "oddPage": pf_print_format["footer"], + "evenPage": pf_print_format["footer"], + "lastPage": pf_print_format["footer"], + } + object_to_save["print_designer_print_format"] = frappe.json.dumps(pf_print_format) frappe.set_value( "Print Format", pf.name, - { - "print_designer_header": frappe.json.dumps(header_data), - "print_designer_body": frappe.json.dumps(bodyPage), - "print_designer_footer": frappe.json.dumps(footer_data), - "print_designer_settings": frappe.json.dumps(settings), - }, + object_to_save, ) return print_formats