Skip to content

Commit

Permalink
[FIX] website: fix by comment
Browse files Browse the repository at this point in the history
  • Loading branch information
duyquyen96 committed Jul 19, 2023
1 parent 8526392 commit 0741bd9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
sudo npm install -g less less-plugin-clean-css
pip install -q -r odoo/requirements.txt
pip install --ignore-installed \
git+https://github.com/OCA/openupgradelib.git@master
git+https://github.com/duong77476/openupgradelib.git@master_imp_boostrap4_to_5_transformation
# this is for v15 l10n_eg_edi_eta which crashes without it
pip install asn1crypto
- name: Test data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

@openupgrade.migrate()
def migrate(env, version):
openupgrade.delete_records_safely_by_xml_id(env, ["website.website_menu"])
openupgrade.load_data(env.cr, "website", "16.0.1.0/noupdate_changes.xml")
39 changes: 15 additions & 24 deletions openupgrade_scripts/scripts/website/16.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,31 @@ def _fill_partner_id_if_null(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE website_visitor
SET partner_id = CASE
WHEN length(access_token) != 32 THEN CAST(access_token AS integer)
ELSE partner_id
END
WHERE partner_id IS NULL;
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, rl.id
FROM website w
CROSS JOIN res_lang rl
WHERE w.id NOT IN (SELECT website_id FROM website_lang_rel)
AND rl.active = true;
""",
)
websites = env["website"].search([("language_ids", "=", False)])
for website in websites:
website.write({"language_ids": [(4, website.default_lang_id.id)]})


def keep_the_first_domain_when_duplicate(env):
def _fill_homepage_url(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE website
SET domain = NULL
WHERE id NOT IN (
SELECT MIN(id)
FROM website
GROUP BY domain
SET homepage_url = (
SELECT url
FROM website_page
WHERE website_page.id = website.homepage_id
);
""",
)
Expand Down Expand Up @@ -96,5 +87,5 @@ def migrate(env, version):
openupgrade.rename_xmlids(env.cr, _xmlids_renames)
openupgrade.delete_records_safely_by_xml_id(env, _xmlids_delete)
delete_constraint_website_visitor_partner_uniq(env)
keep_the_first_domain_when_duplicate(env)
boostrap_5_migration(env)
_fill_homepage_url(env)
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ DEL ir.model.access: website.access_website_ir_ui_view_publisher
# NOTHING TO DO

NEW ir.model.constraint: website.constraint_website_domain_unique

# DONE: Having duplicate domains will keep the first one in pre-migration

DEL ir.model.constraint: website.constraint_website_visitor_partner_uniq

# DONE: safely delete pre-migration
Expand Down

0 comments on commit 0741bd9

Please sign in to comment.