From 470f6228a736279e7dec1a30c62943e0adb72bef Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Wed, 19 Jul 2023 17:09:09 +0200 Subject: [PATCH] [OU-ADD] website_sale: replace content in product custom_text TT44424 --- .../website_sale/14.0.1.0/post-migration.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/openupgrade_scripts/scripts/website_sale/14.0.1.0/post-migration.py b/openupgrade_scripts/scripts/website_sale/14.0.1.0/post-migration.py index 9ae016aeb654..eb4209b22196 100644 --- a/openupgrade_scripts/scripts/website_sale/14.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/website_sale/14.0.1.0/post-migration.py @@ -1,10 +1,36 @@ # Copyright (C) 2021 Open Source Integrators # Copyright 2021 ForgeFlow S.L. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import re from openupgradelib import openupgrade +def extract_custom_product_page_term_conditions(env): + """Replace Terms and Conditions content in the new v14 template so as not to lose + content from previous versions if it has been customised.""" + product_custom_text_view = env.ref("website_sale.product_custom_text") + product_custom_text_arch = product_custom_text_view.arch_db + product_custom_text_pattern = r'

(.*?)

' + product_matches, *_ = re.findall(product_pattern, product_arch, re.DOTALL) + if product_matches: + new_arch = product_custom_text_arch.replace( + product_custom_text_content[0], product_matches[0] + ) + product_custom_text_view.copy( + {"website_id": view.website_id.id, "arch_db": new_arch} + ) + + @openupgrade.migrate() def migrate(env, version): # set simple ribbons (simple case): @@ -57,3 +83,4 @@ def migrate(env, version): WHERE module = 'website_sale' and name = 'image_full' """, ) + extract_custom_product_page_term_conditions(env)