__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from . import controllers
  3. from . import models
  4. from . import wizard
  5. import odoo
  6. from odoo import api, SUPERUSER_ID
  7. from odoo.http import request
  8. from functools import partial
  9. def uninstall_hook(cr, registry):
  10. # Force remove ondelete='cascade' elements,
  11. # This might be prevented by another ondelete='restrict' field
  12. # TODO: This should be an Odoo generic fix, not a website specific one
  13. env = api.Environment(cr, SUPERUSER_ID, {})
  14. website_domain = [('website_id', '!=', False)]
  15. env['ir.asset'].search(website_domain).unlink()
  16. env['ir.ui.view'].search(website_domain).with_context(active_test=False, _force_unlink=True).unlink()
  17. # Cleanup records which are related to websites and will not be autocleaned
  18. # by the uninstall operation. This must be done here in the uninstall_hook
  19. # as during an uninstallation, `unlink` is not called for records which were
  20. # created by the user (not XML data). Same goes for @api.ondelete available
  21. # from 15.0 and above.
  22. env['website'].search([])._remove_attachments_on_website_unlink()
  23. # Properly unlink website_id from ir.model.fields
  24. def rem_website_id_null(dbname):
  25. db_registry = odoo.modules.registry.Registry.new(dbname)
  26. with db_registry.cursor() as cr:
  27. env = api.Environment(cr, SUPERUSER_ID, {})
  28. env['ir.model.fields'].search([
  29. ('name', '=', 'website_id'),
  30. ('model', '=', 'res.config.settings'),
  31. ]).unlink()
  32. cr.postcommit.add(partial(rem_website_id_null, cr.dbname))
  33. def post_init_hook(cr, registry):
  34. env = api.Environment(cr, SUPERUSER_ID, {})
  35. env['ir.module.module'].update_theme_images()
  36. if request:
  37. env = env(context=request.default_context())
  38. request.website_routing = env['website'].get_current_website().id