Before this commit, this flow was broken: - Install website - Create a new website of your own (not using the one created automatically from XML data) - Choose another color palette for that website - Uninstall the website app - Reinstall the website app - Try to choose another color palette for any website => It does not work Indeed, after the uninstallation, the DB is left in an invalid state: the SCSS customizations attachments of the website that was created by the user are not removed, they just have their website_id field emptied. Some code made at [1] was already there to remove those attachments. The problem is that it only worked for websites which were created by XML data (at website installation), not by the user. Indeed, the `unlink` method is not called during uninstallation to remove records that were created by the user, thus the `unlink` override was not called either. See [2] for some details. This fixes the issues by moving this attachment cleaning code in a dedicated method, called in `unlink` but also in the `uninstall_hook` of the website app. This also takes the opportunity to refactor the code involved, in particular to not even consider customized attachments which do not have a website_id. [1]: https://github.com/odoo/odoo/commit/2f361bec36dff09181b96d140d62c477cdf013a1 [2]: https://github.com/odoo/odoo/pull/97852#pullrequestreview-1067851656 opw-3127531 closes odoo/odoo#110338 X-original-commit: 988eafa03b57be3b3a7f110650c61ce8fda88e31 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from . import controllers
|
|
from . import models
|
|
from . import wizard
|
|
|
|
import odoo
|
|
from odoo import api, SUPERUSER_ID
|
|
from odoo.http import request
|
|
from functools import partial
|
|
|
|
|
|
def uninstall_hook(cr, registry):
|
|
# Force remove ondelete='cascade' elements,
|
|
# This might be prevented by another ondelete='restrict' field
|
|
# TODO: This should be an Odoo generic fix, not a website specific one
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
website_domain = [('website_id', '!=', False)]
|
|
env['ir.asset'].search(website_domain).unlink()
|
|
env['ir.ui.view'].search(website_domain).with_context(active_test=False, _force_unlink=True).unlink()
|
|
|
|
# Cleanup records which are related to websites and will not be autocleaned
|
|
# by the uninstall operation. This must be done here in the uninstall_hook
|
|
# as during an uninstallation, `unlink` is not called for records which were
|
|
# created by the user (not XML data). Same goes for @api.ondelete available
|
|
# from 15.0 and above.
|
|
env['website'].search([])._remove_attachments_on_website_unlink()
|
|
|
|
# Properly unlink website_id from ir.model.fields
|
|
def rem_website_id_null(dbname):
|
|
db_registry = odoo.modules.registry.Registry.new(dbname)
|
|
with db_registry.cursor() as cr:
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
env['ir.model.fields'].search([
|
|
('name', '=', 'website_id'),
|
|
('model', '=', 'res.config.settings'),
|
|
]).unlink()
|
|
|
|
cr.postcommit.add(partial(rem_website_id_null, cr.dbname))
|
|
|
|
|
|
def post_init_hook(cr, registry):
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
env['ir.module.module'].update_theme_images()
|
|
|
|
if request:
|
|
env = env(context=request.default_context())
|
|
request.website_routing = env['website'].get_current_website().id
|