Skip to content

Commit

Permalink
[MIG] website: Handle Bootstrap 3->4 and Less->Scss
Browse files Browse the repository at this point in the history
In case a user has customized any Less attachments, these are disabled because 99% of the times it will fail: Syntax from Scss and Less is different, there may not be a `lessc` executable in the Odoo 12 environment, and inherited views would probably fail finding the node to replace from XPath.

Automated resilient conversion between Less and Scss is close to impossible.

To avoid problems, these views are disabled. You are still able to fix and reenable them manually as needed.

In Odoo v12, the standard behavior when a user modifies a website template is to create a modified copy which is specific to the current website (a.k.a. COW 🐮).

To benefit from this new behavior, when migrating a website from Odoo 11 to 12:

1. If a website-specific view exists, it is migrated in place.
2. Website-agnostic views are migrated in a COW 🐮 view, specific for each preexisting website.
3. Webiste-agnostic views are marked as `noupdate=0`, so when starting a new website, you have the updated views as a starting point. To make this work, all this conversion had to be made in the pre-migration stage.
4. The new copies will have a hidden migration column that indicates from which view was it copied.
5. If the views were using any default images from snippets, they will be stored in the filestore now.

To make this work, OCA/openupgradelib#148 is needed.
  • Loading branch information
yajo committed Jun 14, 2019
1 parent 508ae43 commit 4f809ff
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 119 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 0 additions & 90 deletions addons/website/migrations/12.0.1.0/noupdate_changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,6 @@
<field name="datas_fname">s_text_image_default_image.jpg</field>
<field name="url">/website/static/src/img/snippets_demo/s_text_image.jpg</field>
</record>
<record id="contactus" model="ir.ui.view">
<field name="arch" type="xml">
<t name="Contact Us" t-name="website.contactus">
<t t-call="website.layout">
<div id="wrap">
<div class="oe_structure">
<section class="pt8 pb8">
<div class="container">
<div class="row s_nb_column_fixed">
<div class="col-lg-12 s_title pt16 pb16">
<h1>Contact us</h1>
</div>
</div>
</div>
</section>
</div>
<div class="container mt-2">
<div class="row">
<div class="col-lg-8">
<div class="oe_structure">
<section class="s_text_block">
<div class="container">
<div class="row">
<div class="col-lg-12">
<p>
Contact us about anything related to our company or services.<br/>
We'll do our best to get back to you as soon as possible.
</p>
</div>
</div>
</div>
</section>
</div>
<div class="text-center my-3" name="mail_button">
<a role="button" t-attf-href="mailto:{{ res_company.email }}" class="btn btn-primary" id="o_contact_mail">Send us an email</a>
</div>
</div>
<div class="col-lg-4">
<t t-call="website.company_description"/>
</div>
</div>
</div>
<div class="oe_structure mt-2"/>
</div>
</t>
</t>
</field>
</record>
<record id="main_menu" model="website.menu">
<field name="website_id"/>
<field name="name">Default Main Menu</field>
Expand All @@ -76,46 +28,4 @@
<field name="website_id"/>
<field name="page_id"/>
</record>
<record id="aboutus" model="ir.ui.view">
<field name="arch" type="xml">
<t name="About us" t-name="website.aboutus">
<t t-call="website.layout">
<div id="wrap">
<div class="oe_structure">
<section class="pt8 pb8">
<div class="container">
<div class="row s_nb_column_fixed">
<div class="col-lg-12 s_title pt16 pb16">
<h1 class="text-center">About us</h1>
<h3 class="text-muted text-center">Great products for great people</h3>
</div>
</div>
</div>
</section>
<section class="s_text_image pt8 pb8">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 pt16 pb16">
<p>
We are a team of passionate people whose goal is to improve everyone's
life through disruptive products. We build great products to solve your
business problems.
</p>
<p>
Our products are designed for small to medium size companies willing to optimize
their performance.
</p>
</div>
<div class="col-lg-6 pt16 pb16">
<img src="/website/static/src/img/library/business_conference.jpg" class="img img-fluid shadow" alt="Our Team"/>
</div>
</div>
</div>
</section>
</div>
</div>
</t>
</t>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ NEW res.groups: website.group_multi_website
NEW res.users: base.user_admin (noupdate)
DEL web.planner: website.planner_website
# NOTHING TO DO

NEW website.menu: website.menu_home (noupdate)
DEL website.menu: website.menu_homepage (noupdate)
# DONE: Renamed
99 changes: 70 additions & 29 deletions addons/website/migrations/12.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2018-19 Eficent <http://www.eficent.com>
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from psycopg2.extensions import AsIs

from openupgradelib import openupgrade


Expand All @@ -16,6 +18,15 @@ def assign_theme(env):
websites.write({'theme_id': theme_module.id})


def enable_multiwebsites(env):
websites = env["website"].search([])
if len(websites) > 1:
wizard = env["res.config.settings"].create({
"group_multi_website": True,
})
wizard.execute()


def fill_website_socials(cr):
openupgrade.logged_query(
cr, """
Expand All @@ -32,35 +43,65 @@ def fill_website_socials(cr):
)


def apply_bootstrap_4(view):
text = view.arch_db
# TO BE FILLED
view.arch_db = text


def bootstrap_4_migration(env):
pages = env['website.page'].search([])
views = pages.mapped('view_id').filtered(
lambda v: v.type == 'qweb' and not v.xml_id)
for view in views:
apply_bootstrap_4(view)


def apply_copy_views(env):
def sync_menu_views_pages_websites(env):
# Main menu and children must be website-agnostic
main_menu = env.ref('website.main_menu')
child_menus = env["website.menu"].search([
("id", "child_of", main_menu.id),
("website_id", "!=", False),
])
child_menus.write({"website_id": False})
# Duplicate the main menu for main website
website = env["website"].get_current_website()
website.copy_menu_hierarchy(main_menu)
# Find views that were website-specified in pre stage
col_name = openupgrade.get_legacy_name("bs4_migrated_from")
env.cr.execute(
"""
SELECT website_page_id, website_id
FROM website_website_page_rel
"""
"SELECT %s, id FROM %s WHERE %s IS NOT NULL",
(
AsIs(col_name),
AsIs(env["ir.ui.view"]._table),
AsIs(col_name),
)
)
pages = {}
for page_id, website_id in env.cr.fetchall():
if page_id not in pages:
pages[page_id] = []
pages[page_id].append(website_id)
for page in env['website.page'].browse(list(pages)):
for website in env['website'].browse(list(pages[page.id])):
page.copy({'website_id': website.id})
for agnostic_view_id, specific_view_id in env.cr.fetchall():
# Create website-specific page for the copied view
agnostic_view = env["ir.ui.view"].browse(agnostic_view_id)
specific_view = env["ir.ui.view"].browse(specific_view_id)
agnostic_page = agnostic_view.first_page_id
if not agnostic_page:
continue
specific_page = env["website.page"].search([
("url", "=", agnostic_page.url),
("website_id", "=", specific_view.website_id.id),
])
if not specific_page:
specific_page = agnostic_page.copy({
"is_published": agnostic_page.is_published,
"url": agnostic_page.url,
"view_id": specific_view_id,
"website_id": specific_view.website_id.id,
})
elif specific_page.view_id == agnostic_view:
specific_page.view_id = specific_view_id
# Create website-specific menu for the copied page
specific_menu = env["website.menu"].search([
("website_id", "=", specific_page.website_id.id),
("url", "=", specific_page.url),
], limit=1)
if specific_menu:
if specific_menu.page_id:
specific_menu.page_id = specific_page
else:
agnostic_menu = env["website.menu"].search([
("website_id", "=", False),
("url", "=", specific_page.url),
], limit=1)
if agnostic_menu:
agnostic_menu.copy({
"website_id": specific_page.website_id.id,
"page_id": agnostic_menu.page_id.id and specific_page.id,
})


@openupgrade.migrate()
Expand All @@ -69,8 +110,6 @@ def migrate(env, version):
assign_theme(env)
fill_website_socials(cr)
env['website.menu']._parent_store_compute()
bootstrap_4_migration(env)
apply_copy_views(env)
openupgrade.load_data(
cr, 'website', 'migrations/12.0.1.0/noupdate_changes.xml')
openupgrade.delete_records_safely_by_xml_id(
Expand All @@ -80,3 +119,5 @@ def migrate(env, version):
'website.action_module_website',
],
)
enable_multiwebsites(env)
sync_menu_views_pages_websites(env)
Loading

0 comments on commit 4f809ff

Please sign in to comment.