diff --git a/openupgrade_scripts/apriori.py b/openupgrade_scripts/apriori.py index ad2269309ac..2d492a7aef6 100644 --- a/openupgrade_scripts/apriori.py +++ b/openupgrade_scripts/apriori.py @@ -28,3 +28,10 @@ # odoo # OCA/... } + +# Modules dropped from the distribution. base pre-migration marks them +# ``to remove`` so Odoo uninstalls their views and assets. +removed_modules = [ + # odoo/design-themes: snippets library removed in 20.0, not folded into website + "theme_common", +] diff --git a/openupgrade_scripts/scripts/base/20.0.1.3/pre-migration.py b/openupgrade_scripts/scripts/base/20.0.1.3/pre-migration.py new file mode 100644 index 00000000000..6c984afbc63 --- /dev/null +++ b/openupgrade_scripts/scripts/base/20.0.1.3/pre-migration.py @@ -0,0 +1,37 @@ +# Copyright 2026 Odoo Community Association (OCA) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + +# pylint: disable=odoo-addons-relative-import +from odoo.addons.openupgrade_scripts.apriori import removed_modules + + +def _remove_obsolete_modules(env): + """Mark modules that disappeared from the distribution as ``to remove``. + + Odoo logs ``module : manifest not found`` from ``button_upgrade`` + (that runs before migration scripts) and would leave the row ``to upgrade``. + ``base`` pre-migration moves the modules listed in ``apriori.removed_modules`` + to ``to remove``. The end of the upgrade then calls ``module_uninstall``, + which deletes the module's views and assets and sets the state to + ``uninstalled``. ``theme_common`` (design-themes) is the 20.0 case: the + snippets library was removed and was not merged into ``website``. + """ + if not removed_modules: + return + openupgrade.logged_query( + env.cr, + """ + UPDATE ir_module_module + SET state = 'to remove' + WHERE name IN %s + AND state IN ('installed', 'to upgrade', 'to install') + """, + (tuple(removed_modules),), + ) + + +@openupgrade.migrate() +def migrate(env, version): + _remove_obsolete_modules(env)