diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index da47299fcdc5..49f0b7bdd6c7 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -924,7 +924,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | website_sale_wishlist | |No DB layout changes. | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| website_slides | | | +| website_slides | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | website_slides_forum | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/website_slides/16.0.2.6/post-migration.py b/openupgrade_scripts/scripts/website_slides/16.0.2.6/post-migration.py new file mode 100644 index 000000000000..32e0c9c390c9 --- /dev/null +++ b/openupgrade_scripts/scripts/website_slides/16.0.2.6/post-migration.py @@ -0,0 +1,69 @@ +# Copyright 2023 Viindoo - Nguyễn Việt Lâm +# Copyright 2024 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +def _fill_source_type_external(env): + """Switch to external for those with `google_drive_id`, that are the only where + these applies: + https://github.com/odoo/odoo/blob/42bcc3ef284ca355e2323641176573b53e7d2e28/addons/ + website_slides/controllers/main.py#L1197 + """ + env["slide.slide"].search([]).filtered("google_drive_id").source_type = "external" + + +def _fill_nbr_article(env): + """Fill the values recreating the compute method, but only for the field + nbr_article. + """ + for source in ["slide", "channel"]: + if source == "slide": + records = env["slide.slide"].search([("is_category", "=", True)]) + field = "category_id" + else: + records = env["slide.channel"].search([]) + field = "channel_id" + domain = [ + ("is_published", "=", True), + ("is_category", "=", False), + (field, "in", records.ids), + ] + res = env["slide.slide"]._read_group( + domain, + [field, "slide_category"], + [field, "slide_category"], + lazy=False, + ) + category_stats = records._compute_slides_statistics_category(res) + for record in records: + record.nbr_article = category_stats.get( + record._origin.id, {"nb_article": 0} + )["nbr_article"] + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env.cr, "website_slides", "16.0.2.6/noupdate_changes.xml") + openupgrade.delete_record_translations( + env.cr, + "website_slides", + [ + "mail_template_channel_completed", + "mail_template_slide_channel_invite", + ], + ["name", "subject", "description"], + ) + openupgrade.delete_record_translations( + env.cr, + "website_slides", + ["mail_template_slide_channel_invite"], + ["name", "description"], + ) + openupgrade.delete_record_translations( + env.cr, + "website_slides", + ["slide_template_published", "slide_template_shared"], + ) + _fill_source_type_external(env) + _fill_nbr_article(env) diff --git a/openupgrade_scripts/scripts/website_slides/16.0.2.6/pre-migration.py b/openupgrade_scripts/scripts/website_slides/16.0.2.6/pre-migration.py new file mode 100644 index 000000000000..2f04f270465f --- /dev/null +++ b/openupgrade_scripts/scripts/website_slides/16.0.2.6/pre-migration.py @@ -0,0 +1,98 @@ +# Copyright 2023 Viindoo - Nguyễn Việt Lâm +# Copyright 2024 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +renamed_fields = [ + ("slide.slide", "slide_slide", "datas", "binary_content"), + ("slide.channel", "slide_channel", "share_template_id", "share_slide_template_id"), +] +xml_ids_to_rename = [ + ( + "website_slides.rule_slide_slide_resource_manager", + "website_slides.rule_slide_slide_resource_downloadable_manager", + ), +] + + +def _create_and_fill_data_from_slide_type_to_slide_category(env): + openupgrade.copy_columns( + env.cr, {"slide_slide": [("slide_type", "slide_category", None)]} + ) + openupgrade.map_values( + env.cr, + "slide_type", + "slide_category", + [("webpage", "article"), ("presentation", "document")], + table="slide_slide", + ) + openupgrade.rename_columns(env.cr, {"slide_slide": [("slide_type", None)]}) + + +def _create_and_fill_data_for_source_type(env): + openupgrade.logged_query( + env.cr, + "ALTER TABLE slide_slide ADD COLUMN IF NOT EXISTS source_type VARCHAR", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE slide_slide + SET source_type = CASE + WHEN url IS NOT NULL AND slide_category = 'document' THEN 'external' + ELSE 'local_file' + END + """, + ) + + +def _create_column_and_migrate_data_from_slide_link_to_slide_resource(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE slide_slide_resource + ADD COLUMN IF NOT EXISTS link VARCHAR, + ADD COLUMN IF NOT EXISTS resource_type VARCHAR + """, + ) + openupgrade.logged_query( + env.cr, + "UPDATE slide_slide_resource SET resource_type = 'file'", + ) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO slide_slide_resource + (name, link, slide_id, resource_type) + SELECT name, link, slide_id, 'url' + FROM slide_slide_link + """, + ) + + +def _create_nbr_article(env): + """Pre-create and fill these fields for avoiding KeyError crashes as the compute + method uses read_group. + """ + openupgrade.logged_query( + env.cr, + "ALTER TABLE slide_channel ADD COLUMN IF NOT EXISTS nbr_article INT4", + ) + openupgrade.logged_query( + env.cr, + "ALTER TABLE slide_slide ADD COLUMN IF NOT EXISTS nbr_article INT4 DEFAULT 0", + ) + openupgrade.logged_query( + env.cr, + "ALTER TABLE slide_slide ALTER COLUMN nbr_article DROP DEFAULT", + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_fields(env, renamed_fields) + openupgrade.rename_xmlids(env.cr, xml_ids_to_rename) + _create_and_fill_data_from_slide_type_to_slide_category(env) + _create_column_and_migrate_data_from_slide_link_to_slide_resource(env) + _create_and_fill_data_for_source_type(env) + _create_nbr_article(env) diff --git a/openupgrade_scripts/scripts/website_slides/16.0.2.6/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/website_slides/16.0.2.6/upgrade_analysis_work.txt new file mode 100644 index 000000000000..3231a053a9ac --- /dev/null +++ b/openupgrade_scripts/scripts/website_slides/16.0.2.6/upgrade_analysis_work.txt @@ -0,0 +1,122 @@ +---Models in module 'website_slides'--- +obsolete model slide.slide.link +website_slides / slide.slide.link / link (char) : DEL required +website_slides / slide.slide.link / name (char) : DEL required +website_slides / slide.slide.link / slide_id (many2one) : DEL relation: slide.slide, required +# DONE: move data from slide.slide.link to slide.slide.resource in pre-migration +# REASON: previously website_slides seperate slide.slide.link and slide.slide.resource one is store url another store file. Now combined into slide.slide.resource + +---Fields in module 'website_slides'--- +website_slides / slide.channel / cover_properties (text) : NEW hasdefault: default +# NOTHING TO DO: New feature to customize the cover of the course. + +website_slides / slide.channel / nbr_article (integer) : NEW isfunction: function, stored +website_slides / slide.slide / nbr_article (integer) : NEW isfunction: function, stored +# DONE: pre-migration: Pre-create and fill the field for avoiding KeyError in the compute as it uses `read_group` method. +# DONE: post-migration: Fill the field using ORM recreating the compute method, as the computation by SQL gets hard and it doesn't worth due to the scope. + +website_slides / slide.channel / nbr_presentation (integer) : DEL +website_slides / slide.channel / nbr_webpage (integer) : DEL +# NOTHING TO DO: executed by ORM + +website_slides / slide.channel / share_channel_template_id (many2one): NEW relation: mail.template, hasdefault: default +# NOTHING TO DO: This value is needed for sharing the channel, so better to have one filled, and the default one given by ORM is OK. + +website_slides / slide.channel / share_slide_template_id (many2one): NEW relation: mail.template, hasdefault: default +website_slides / slide.channel / share_template_id (many2one) : DEL relation: mail.template +website_slides / slide.slide / binary_content (binary) : NEW attachment: True +website_slides / slide.slide / datas (binary) : DEL attachment: True +# DONE: pre-migration: renamed fields + +website_slides / slide.slide / document_id (char) : DEL +# NOTHING TO DO: Following the logic where this field was involved, now it is computed on the fly (stored=False) from URL. + +website_slides / slide.slide / embed_ids (one2many) : NEW relation: slide.embed +website_slides / slide.slide / embedcount_ids (one2many) : DEL relation: slide.embed +# NOTHING TO DO: rename from embedcount_ids to embed_ids still one2many type + +website_slides / slide.slide / link_ids (one2many) : DEL relation: slide.slide.link +website_slides / slide.slide / mime_type (char) : DEL +website_slides / slide.slide / nbr_presentation (integer) : DEL +website_slides / slide.slide / nbr_webpage (integer) : DEL +# NOTHING TO DO + +website_slides / slide.slide / slide_category (selection) : NEW required, selection_keys: ['article', 'document', 'infographic', 'quiz', 'video'], hasdefault: default +# DONE: pre-migration: copy column slide_type + map values that changes + +website_slides / slide.slide / slide_type (selection) : selection_keys is now '['article', 'doc', 'google_drive_video', 'image', 'pdf', 'quiz', 'sheet', 'slides', 'vimeo_video', 'youtube_video']' ('['document', 'infographic', 'presentation', 'quiz', 'video', 'webpage']') +# NOTHING TO DO: Let ORM handle recomputes this field + +website_slides / slide.slide / source_type (selection) : NEW required, selection_keys: ['external', 'local_file'], hasdefault: default +# DONE: post-migration: Switch to external for those with `google_drive_id`, that are the only where these applies: https://github.com/odoo/odoo/blob/42bcc3ef284ca355e2323641176573b53e7d2e28/addons/website_slides/controllers/main.py#L1197 + +website_slides / slide.slide.resource / file_name (char) : NEW +# NOTHING TO DO + +website_slides / slide.slide.resource / link (char) : NEW hasdefault: compute +website_slides / slide.slide.resource / resource_type (selection) : NEW required, selection_keys: ['file', 'url'] +# DONE: pre-migration: create column and fill data + +---XML records in module 'website_slides'--- +NEW ir.actions.act_window: website_slides.action_slide_channel_pages_list +NEW ir.actions.act_window: website_slides.slide_channel_action_add +NEW ir.actions.act_window: website_slides.slide_embed_action +NEW ir.actions.act_window: website_slides.slide_slide_partner_action_from_slide +DEL ir.actions.act_window: website_slides.rating_rating_action_slide_channel_report +NEW ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_view_form +NEW ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_view_graph +NEW ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_view_kanban +NEW ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_view_pivot +NEW ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_view_tree +NEW ir.actions.act_window.view: website_slides.slide_channel_action_report_view_form +NEW ir.actions.act_window.view: website_slides.slide_channel_action_report_view_graph +NEW ir.actions.act_window.view: website_slides.slide_channel_action_report_view_pivot +NEW ir.actions.act_window.view: website_slides.slide_channel_action_report_view_tree +NEW ir.actions.act_window.view: website_slides.slide_slide_action_report_view_form +NEW ir.actions.act_window.view: website_slides.slide_slide_action_report_view_graph +NEW ir.actions.act_window.view: website_slides.slide_slide_action_report_view_pivot +NEW ir.actions.act_window.view: website_slides.slide_slide_action_report_view_tree +DEL ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_report_view_graph +DEL ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_report_view_pivot +DEL ir.actions.act_window.view: website_slides.rating_rating_action_slide_channel_report_view_tree +# NOTHING TO DO + +DEL ir.model.access: website_slides.access_slide_slide_link_all +DEL ir.model.access: website_slides.access_slide_slide_link_officer +# NOTHING TO DO + +NEW ir.model.constraint: website_slides.constraint_slide_channel_partner_channel_partner_uniq +NEW ir.model.constraint: website_slides.constraint_slide_channel_partner_check_completion +NEW ir.model.constraint: website_slides.constraint_slide_slide_partner_check_vote +NEW ir.model.constraint: website_slides.constraint_slide_slide_partner_slide_partner_uniq +NEW ir.model.constraint: website_slides.constraint_slide_slide_resource_check_file_type +NEW ir.model.constraint: website_slides.constraint_slide_slide_resource_check_url +# NOTHING TO DO + + +NEW ir.rule: website_slides.rule_slide_slide_resource_downloadable_manager (noupdate) +DEL ir.rule: website_slides.rule_slide_slide_resource_manager (noupdate) +# DONE: rename xmlid in pre-migration + +NEW ir.ui.menu: website_slides.menu_slide_channel_pages +DEL ir.ui.menu: website_slides.website_slides_menu_courses_reviews +NEW ir.ui.view: website_slides.course_join +NEW ir.ui.view: website_slides.rating_rating_view_form_slides +NEW ir.ui.view: website_slides.rating_rating_view_tree_slide_channel +NEW ir.ui.view: website_slides.slide_channel_pages_kanban_view +NEW ir.ui.view: website_slides.slide_channel_pages_tree_view +NEW ir.ui.view: website_slides.slide_channel_view_form_add +NEW ir.ui.view: website_slides.slide_channel_view_pivot +NEW ir.ui.view: website_slides.slide_embed_view_search +NEW ir.ui.view: website_slides.slide_embed_view_tree +NEW ir.ui.view: website_slides.slide_sidebar_done_button +NEW ir.ui.view: website_slides.slide_slide_partner_view_form +NEW ir.ui.view: website_slides.slide_slide_partner_view_search +NEW ir.ui.view: website_slides.slide_slide_partner_view_tree +NEW ir.ui.view: website_slides.slide_slide_view_tree_report +NEW ir.ui.view: website_slides.snippet_options +DEL ir.ui.view: website_slides.rating_rating_view_kanban_slide_channel +DEL ir.ui.view: website_slides.slide_edit_options +DEL ir.ui.view: website_slides.user_navbar_inherit_website_slides +NEW mail.template: website_slides.mail_template_channel_shared (noupdate) +# NOTHING TO DO