From 81004e687af28ddc4822297aed99b69daf63d1f6 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Wed, 29 Nov 2023 13:25:11 +0100 Subject: [PATCH] [OU-FIX] website: Extract copyright information from existing website Previous code was ignoring possible customizations on the copyright information, as it took it from the master template. With this change, the information is taken from the customized template if exists, or the master otherwise, using the existing CoW mechanism for getting it in a simple way. TT44254 --- .../website/15.0.1.0/post-migration.py | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/openupgrade_scripts/scripts/website/15.0.1.0/post-migration.py b/openupgrade_scripts/scripts/website/15.0.1.0/post-migration.py index 00764aae19da..bb23de54d056 100644 --- a/openupgrade_scripts/scripts/website/15.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/website/15.0.1.0/post-migration.py @@ -8,34 +8,39 @@ def extract_footer_copyright_company_name(env): content from previous versions if it has been customised, or directly put the company name if not customized (which is the previous value). """ - main_copyright_view = env.ref("website.footer_copyright_company_name") - if not main_copyright_view: - return - main_copyright_arch = main_copyright_view.arch_db - main_copyright_pattern = r'(.*?)<\/span>' - main_copyright_matches = re.findall( - main_copyright_pattern, - main_copyright_arch, - re.DOTALL, - ) for website in env["website"].search([]): - view = env["ir.ui.view"].search( - [("key", "=", "website.layout"), ("website_id", "=", website.id)] + main_copyright_view = website.with_context(website_id=website.id).viewref( + "website.footer_copyright_company_name" ) - website_layout_arch = view.arch_db or "" - website_layout_pattern = ( + main_copyright_arch = main_copyright_view.arch_db + main_copyright_pattern = ( r'(.*?)<\/span>' ) - website_layout_matches = re.findall( - website_layout_pattern, website_layout_arch, re.DOTALL + main_copyright_matches = re.findall( + main_copyright_pattern, + main_copyright_arch, + re.DOTALL, ) - new_arch = main_copyright_arch.replace( - main_copyright_matches[0], - website_layout_matches - and website_layout_matches[0] - or f"Copyright © {website.company_id.name}", - ) - main_copyright_view.with_context(website_id=website.id).arch_db = new_arch + if main_copyright_matches: + website_layout_view = website.with_context(website_id=website.id).viewref( + "website.layout" + ) + website_layout_arch = website_layout_view.arch_db or "" + website_layout_pattern = ( + r'(.*?)<\/span>' + ) + website_layout_matches = re.findall( + website_layout_pattern, website_layout_arch, re.DOTALL + ) + new_arch = re.sub( + main_copyright_pattern, + website_layout_matches[0] + if website_layout_matches + else f'' + f"Copyright © {website.company_id.name}", + main_copyright_arch, + ) + main_copyright_view.with_context(website_id=website.id).arch = new_arch def update_website_form_call(env):