Skip to content

Commit

Permalink
[OU-ADD] website_sale: replace content in product custom_text
Browse files Browse the repository at this point in the history
TT44424
  • Loading branch information
pilarvargas-tecnativa committed Jul 26, 2023
1 parent 44f3dae commit 470f622
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
# Copyright (C) 2021 Open Source Integrators <https://www.opensourceintegrators.com/>
# Copyright 2021 ForgeFlow S.L. <https://www.forgeflow.com>
# 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'<p class="text-muted(.*?)<\/p>'
product_custom_text_content, *_ = re.findall(
product_custom_text_pattern, product_custom_text_arch, re.DOTALL
)
product_views = env["ir.ui.view"].search(
[("key", "=", "website_sale.product"), ("website_id", "!=", False)]
)
for view in product_views:
product_arch = view.arch_db
product_pattern = r'<hr\s*/>\s*<p\s+class="text-muted">(.*?)</p>'
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):
Expand Down Expand Up @@ -57,3 +83,4 @@ def migrate(env, version):
WHERE module = 'website_sale' and name = 'image_full'
""",
)
extract_custom_product_page_term_conditions(env)

0 comments on commit 470f622

Please sign in to comment.