Skip to content

Commit

Permalink
Merge pull request #3949 from duyquyen96/16_add_website
Browse files Browse the repository at this point in the history
[16.0][OU-ADD] website
  • Loading branch information
pedrobaeza authored Oct 30, 2023
2 parents 3116d5d + e87daf3 commit 6f13f41
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 3 deletions.
38 changes: 38 additions & 0 deletions openupgrade_scripts/scripts/website/16.0.1.0/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from openupgradelib import openupgrade
from openupgradelib.openupgrade_160 import convert_string_bootstrap_4to5
from psycopg2.extras import Json


def boostrap_5_migration(env):
"""Convert customized website views to Bootstrap 5."""
backup_column = openupgrade.get_legacy_name("arch_db_bs4")
openupgrade.logged_query(
env.cr, f"ALTER TABLE ir_ui_view ADD COLUMN {backup_column} TEST"
)
# Find views to convert
env.cr.execute(
"""
SELECT iuv.id, iuv.arch_db
FROM ir_ui_view iuv
WHERE iuv.type = 'qweb'
"""
)
for id_, arch_db_ in env.cr.fetchall():
if not arch_db_:
continue
new_arch = {
lang: convert_string_bootstrap_4to5(arch_db)
for lang, arch_db in arch_db_.items()
}
if new_arch != arch_db_:
env.cr.execute(
f"UPDATE ir_ui_view SET {backup_column} = arch_db WHERE id=%s",
(id_,),
)
query = "UPDATE ir_ui_view SET arch_db = %s WHERE id = %s"
env.cr.execute(env.cr.mogrify(query, [Json(new_arch), id_]).decode())


@openupgrade.migrate()
def migrate(env, version):
boostrap_5_migration(env)
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="default_website" model="website">
<field name="domain"/>
</record>
<record id="s_masonry_block_default_image_2" model="ir.attachment">
<field name="url">/website/static/src/img/snippets_demo/s_picture.jpg</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env.cr, "website", "16.0.1.0/noupdate_changes.xml")
135 changes: 135 additions & 0 deletions openupgrade_scripts/scripts/website/16.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from lxml import etree
from openupgradelib import openupgrade

_xmlids_renames = [
(
"website.group_website_publisher",
"website.group_website_restricted_editor",
),
(
"website_sale.menu_reporting",
"website.menu_reporting",
),
]

# delete xml xpath for odoo add it again
_xmlids_delete = [
"website.website_configurator",
"website.website_menu",
]


def delete_constraint_website_visitor_partner_uniq(env):
openupgrade.delete_sql_constraint_safely(
env,
"website",
"website_visitor",
"partner_uniq",
)


def _fill_partner_id_if_null(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE website_visitor v
SET partner_id = p.id
FROM res_partner p
WHERE v.partner_id IS NULL
AND length(v.access_token) != 32
AND p.id = CAST(v.access_token AS integer);
""",
)


def _fill_language_ids_if_null(env):
openupgrade.logged_query(
env.cr,
"""
INSERT INTO website_lang_rel (website_id, lang_id)
SELECT w.id, w.default_lang_id
FROM website w
WHERE NOT EXISTS (
SELECT 1
FROM website_lang_rel wlr
WHERE wlr.website_id = w.id
);
""",
)


def _fill_homepage_url(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE website
ADD COLUMN IF NOT EXISTS homepage_url CHARACTER VARYING
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE website
SET homepage_url = website_page.url
FROM website_page
WHERE website_page.id = website.homepage_id
""",
)


def _mig_s_progress_steps_contents(env):
"""Adapt to the new expected format inserted "Steps" snippet."""
views = (
env["ir.ui.view"]
.with_context(active_test=False)
.search(
[
("arch_db", "ilike", '%data-snippet="s_process_steps"%'),
("arch_db", "not ilike", '%s_process_steps_connector_line"%'),
]
)
)
for view in views:
arch = etree.fromstring(view.arch_db)
step_els = arch.xpath("//section[hasclass('s_process_steps')]")
for step in step_els:
if step.get("data-vcss"):
continue
step.set(
"class", step.attrib.get("class") + " s_process_steps_connector_line"
)
step.set("data-vcss", "001")
svg_defs = """
<svg class="s_process_step_svg_defs position-absolute">
<defs>
<marker class="s_process_steps_arrow_head" markerWidth="15"
markerHeight="10" refX="6" refY="6" orient="auto">
<path d="M 2,2 L10,6 L2,10 L6,6 L2,2"
vector-effect="non-scaling-size"/>
</marker>
</defs>
</svg>
"""
step.insert(0, etree.fromstring(svg_defs))
icon_els = step.xpath(".//div[hasclass('s_process_step_icon')]")
for icon in icon_els:
connector = """
<svg class="s_process_step_connector" viewBox="0 0 100 20"
preserveAspectRatio="none">
<path d="M 0 10 L 100 10" vector-effect="non-scaling-stroke"/>
</svg>
"""
parent = icon.getparent()
parent.insert(parent.index(icon), etree.fromstring(connector))
view.arch_db = env["ir.ui.view"]._pretty_arch(arch)


@openupgrade.migrate()
def migrate(env, version):
_fill_partner_id_if_null(env)
_fill_language_ids_if_null(env)
openupgrade.rename_xmlids(env.cr, _xmlids_renames)
openupgrade.delete_records_safely_by_xml_id(env, _xmlids_delete)
delete_constraint_website_visitor_partner_uniq(env)
_fill_homepage_url(env)
_mig_s_progress_steps_contents(env)
109 changes: 109 additions & 0 deletions openupgrade_scripts/scripts/website/16.0.1.0/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---Models in module 'website'---
---Fields in module 'website'---
website / theme.website.menu / mega_menu_classes (char) : NEW
website / theme.website.menu / mega_menu_content (html) : NEW
website / theme.website.menu / use_main_menu_as_parent (boolean): NEW hasdefault: default
website / theme.website.page / footer_visible (boolean) : NEW hasdefault: default
website / theme.website.page / header_color (char) : NEW
website / theme.website.page / header_overlay (boolean) : NEW
website / theme.website.page / header_visible (boolean) : NEW hasdefault: default
website / theme.website.page / is_published (boolean) : NEW
# NOTHING TO DO

website / website / country_group_ids (many2many) : DEL relation: res.country.group
website / website / google_management_client_id (char): DEL
website / website / google_management_client_secret (char): DEL
# NOTHING TO DO: Lost features

website / website / homepage_id (many2one) : DEL relation: website.page
website / website / homepage_url (char) : NEW
# DONE: pre-migration: Fill the URL

website / website / language_ids (many2many) : now required
# DONE: pre-migration: Fill language_ids if null

website / website / plausible_shared_key (char) : NEW
website / website / plausible_site (char) : NEW
website / website.menu / group_ids (many2many) : DEL relation: res.groups
website / website.page / cache_key_expr (char) : DEL
website / website.page / cache_time (integer) : DEL
website / website.visitor / _order : _order is now 'id DESC' ('last_connection_datetime DESC')
website / website.visitor / active (boolean) : DEL
website / website.visitor / name (char) : not stored anymore
website / website.visitor / name (char) : now related
# NOTHING TO DO: New features

website / website.visitor / partner_id (many2one) : now a function
# DONE: pre-migration: Fill partner id if null

---XML records in module 'website'---
DEL ir.actions.act_url: website.start_configurator_act_url
NEW ir.actions.client: website.action_open_website_configurator
NEW ir.actions.client: website.website_configurator
NEW ir.actions.client: website.website_preview
NEW ir.actions.server: website.ir_actions_server_website_analytics
DEL ir.actions.server: website.ir_actions_server_website_google_analytics
NEW ir.asset: website.s_countdown_000_xml
NEW ir.asset: website.s_dynamic_snippet_000_xml
NEW ir.asset: website.s_dynamic_snippet_carousel_000_xml
NEW ir.asset: website.s_image_gallery_000_xml
NEW ir.asset: website.s_map_000_js
NEW ir.asset: website.s_process_steps_001_scss
NEW ir.asset: website.s_searchbar_000_xml
NEW ir.asset: website.s_social_media_000_scss
NEW ir.asset: website.s_website_form_xml
NEW ir.model.access: website.access_website_ir_ui_view_restricted_editor
DEL ir.model.access: website.access_website_ir_ui_view_publisher
# NOTHING TO DO

NEW ir.model.constraint: website.constraint_website_domain_unique
# NOTHING TO DO

DEL ir.model.constraint: website.constraint_website_visitor_partner_uniq
# DONE: pre-migration: drop constraint

DEL ir.rule: website.website_menu (noupdate)
# DONE: pre-migration: safely delete

NEW ir.ui.menu: website.custom_menu_edit_menu
NEW ir.ui.menu: website.menu_ace_editor
NEW ir.ui.menu: website.menu_content
NEW ir.ui.menu: website.menu_current_page
NEW ir.ui.menu: website.menu_edit_menu
NEW ir.ui.menu: website.menu_optimize_seo
NEW ir.ui.menu: website.menu_page_properties
# NOTHING TO DO

NEW ir.ui.menu: website.menu_reporting [renamed from website_sale module]
# DONE: pre-migration: renamed

NEW ir.ui.menu: website.menu_site
NEW ir.ui.menu: website.menu_website_analytics
NEW ir.ui.menu: website.menu_website_preview
DEL ir.ui.menu: website.menu_dashboard
DEL ir.ui.menu: website.menu_visitor_sub_menu
DEL ir.ui.menu: website.menu_website_google_analytics
NEW ir.ui.view: website.404_plausible
NEW ir.ui.view: website.iframefallback
NEW ir.ui.view: website.neutralize_ribbon
NEW ir.ui.view: website.res_config_settings_view_form_inherit_auth_signup
NEW ir.ui.view: website.s_process_steps_options
NEW ir.ui.view: website.s_social_media
NEW ir.ui.view: website.s_social_media_options
NEW ir.ui.view: website.website_page_properties_view_form
NEW ir.ui.view: website.website_pages_kanban_view
DEL ir.ui.view: website.compiled_assets_wysiwyg
DEL ir.ui.view: website.index_management
DEL ir.ui.view: website.list_website_pages
DEL ir.ui.view: website.one_page_line
DEL ir.ui.view: website.publish_short
DEL ir.ui.view: website.s_share_options
DEL ir.ui.view: website.snippet_options_header_brand
DEL ir.ui.view: website.user_navbar
DEL ir.ui.view: website.website_configurator
DEL ir.ui.view: website.website_publisher
# NOTHING TO DO

NEW res.groups: website.group_website_restricted_editor
DEL res.groups: website.group_website_publisher
# DONE: pre-migration: rename group

0 comments on commit 6f13f41

Please sign in to comment.