|
| 1 | +from odoo import api, models |
| 2 | + |
| 3 | + |
| 4 | +class IrModelData(models.Model): |
| 5 | + _inherit = "ir.model.data" |
| 6 | + |
| 7 | + @api.model |
| 8 | + def _module_data_uninstall(self, modules_to_remove): |
| 9 | + # Set a flag to prevent the deletion of tables and columns |
| 10 | + # related to ir.actions.act_multi. |
| 11 | + if "web_ir_actions_act_multi" in modules_to_remove: |
| 12 | + self = self.with_context(uninstall_web_ir_actions_act_multi=True) |
| 13 | + return super(IrModelData, self)._module_data_uninstall(modules_to_remove) |
| 14 | + |
| 15 | + |
| 16 | +class IrModel(models.Model): |
| 17 | + _inherit = "ir.model" |
| 18 | + |
| 19 | + def _drop_table(self): |
| 20 | + # Prevent the deletion of the table. |
| 21 | + # The model is ir.actions.act_multi, but the actual table is ir_actions. |
| 22 | + # This table is a core component and should not be removed. |
| 23 | + if self.env.context.get("uninstall_web_ir_actions_act_multi"): |
| 24 | + self -= self.filtered(lambda model: model.model == "ir.actions.act_multi") |
| 25 | + return super()._drop_table() |
| 26 | + |
| 27 | + |
| 28 | +class IrModelFields(models.Model): |
| 29 | + _inherit = "ir.model.fields" |
| 30 | + |
| 31 | + def _drop_column(self): |
| 32 | + # Prevent the deletion of columns in the ir_actions table. |
| 33 | + # The model is ir.actions.act_multi, but the actual table is ir_actions. |
| 34 | + # Since this table is a core component, its columns should not be deleted. |
| 35 | + if self.env.context.get("uninstall_web_ir_actions_act_multi"): |
| 36 | + self -= self.filtered(lambda field: field.model == "ir.actions.act_multi") |
| 37 | + return super()._drop_column() |
0 commit comments