File: ir_model_data.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (35 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import logging

from odoo import api, models
from odoo.http import request

_logger = logging.getLogger(__name__)


class IrModelData(models.Model):
    _inherit = 'ir.model.data'

    @api.model
    def _process_end_unlink_record(self, record):
        if record._context['module'].startswith('theme_'):
            theme_records = self.env['ir.module.module']._theme_model_names.values()
            if record._name in theme_records:
                # use active_test to also unlink archived models
                # and use MODULE_UNINSTALL_FLAG to also unlink inherited models
                copy_ids = record.with_context({
                    'active_test': False,
                    'MODULE_UNINSTALL_FLAG': True
                }).copy_ids
                if request:
                    # we are in a website context, see `write()` override of
                    # ir.module.module in website
                    current_website = self.env['website'].get_current_website()
                    copy_ids = copy_ids.filtered(lambda c: c.website_id == current_website)

                _logger.info('Deleting %s@%s (theme `copy_ids`) for website %s',
                             copy_ids.ids, record._name, copy_ids.mapped('website_id'))
                copy_ids.unlink()

        return super()._process_end_unlink_record(record)