diff --git a/openupgrade_scripts/apriori.py b/openupgrade_scripts/apriori.py index 4fd0c2e2ffbc..b12174760b07 100644 --- a/openupgrade_scripts/apriori.py +++ b/openupgrade_scripts/apriori.py @@ -71,10 +71,12 @@ # OCA/project "project_description": "project", "project_stage_closed": "project", - # OCA/web - "web_editor_background_color": "web_editor", # OCA/survey "survey_description": "survey", + # OCA/web + "web_editor_background_color": "web_editor", + # OCA/website + "website_cookie_notice": "website", # OCA/... } diff --git a/openupgrade_scripts/scripts/website/14.0.1.0/post-migration.py b/openupgrade_scripts/scripts/website/14.0.1.0/post-migration.py index 1cd51d7cc2fc..d8121dd57854 100644 --- a/openupgrade_scripts/scripts/website/14.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/website/14.0.1.0/post-migration.py @@ -3,7 +3,30 @@ from openupgradelib import openupgrade +def website_cookie_notice_post_migration(env): + cookie_message = env.ref("website.cookie_message", raise_if_not_found=False) + if cookie_message: + websites = env["website"].search([]) + websites.write({"cookies_bar": True}) + env.cr.execute( + """WITH keys AS ( + SELECT key + FROM ir_ui_view iuv + JOIN ir_model_data imd ON (imd.model = 'ir.ui.view' + AND imd.res_id = iuv.id AND module = 'website') + WHERE imd.name IN ('cookie_message', 'cookie_message_container') + ) + SELECT iuv.id + FROM ir_ui_view iuv + JOIN keys ON iuv.key = keys.key""", + ) + view_ids = [x[0] for x in env.cr.fetchall()] + if view_ids: + env["ir.ui.view"].browse(view_ids).unlink() + + @openupgrade.migrate() def migrate(env, version): openupgrade.load_data(env.cr, "website", "14.0.1.0/noupdate_changes.xml") openupgrade.delete_records_safely_by_xml_id(env, ["website.aboutus_page"]) + website_cookie_notice_post_migration(env) diff --git a/openupgrade_scripts/scripts/website/14.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/website/14.0.1.0/pre-migration.py index ff7e1b3f33ed..f4e2c009768f 100644 --- a/openupgrade_scripts/scripts/website/14.0.1.0/pre-migration.py +++ b/openupgrade_scripts/scripts/website/14.0.1.0/pre-migration.py @@ -14,6 +14,31 @@ def assure_website_visitor_partner_is_set(env): ) +def website_cookie_notice_pre_migration(env): + openupgrade.logged_query( + env.cr, + """ + WITH keys AS ( + SELECT key + FROM ir_ui_view iuv + JOIN ir_model_data imd ON ( + imd.model = 'ir.ui.view' AND imd.res_id = iuv.id AND module = 'website') + WHERE imd.name IN ('legal_cookie_policy', 'cookie_banner') + ) + DELETE FROM ir_ui_view iuv + USING keys + WHERE iuv.key = keys.key AND iuv.website_id IS NOT NULL""", + ) + # rename xmlids + openupgrade.rename_xmlids( + env.cr, + [ + ("website.legal_cookie_policy", "website.cookie_policy"), + ("website.cookie_banner", "website.cookies_bar"), + ], + ) + + @openupgrade.migrate() def migrate(env, version): assure_website_visitor_partner_is_set(env) @@ -29,3 +54,4 @@ def migrate(env, version): ], True, ) + website_cookie_notice_pre_migration(env)