Skip to content

Commit

Permalink
[MIG] database_cleanup: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelZilli authored and yankinmax committed Feb 20, 2023
1 parent dbcd7bd commit e937f03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
16 changes: 10 additions & 6 deletions database_cleanup/models/purge_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,38 @@
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError

from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG

_logger = logging.getLogger(__name__)


class IrModel(models.Model):
_inherit = "ir.model"

def _drop_table(self):
"""this function crashes for undefined models"""
existing_model_ids = self.filtered(lambda x: x.model in self.env)
return super(IrModel, existing_model_ids)._drop_table()
self = self.filtered(lambda x: x.model in self.env)
return super()._drop_table()

@api.depends()
def _inherited_models(self):
"""this function crashes for undefined models"""
existing_model_ids = self.filtered(lambda x: x.model in self.env)
return super(IrModel, existing_model_ids)._inherited_models()
self = self.filtered(lambda x: x.model in self.env)
return super()._inherited_models()


class IrModelFields(models.Model):
_inherit = "ir.model.fields"

def _prepare_update(self):
"""this function crashes for undefined models"""
existing = self.filtered(lambda x: x.model in self.env)
return super(IrModelFields, existing)._prepare_update()
self = self.filtered(lambda x: x.model in self.env)
return super()._prepare_update()


class CleanupPurgeLineModel(models.TransientModel):
Expand Down
4 changes: 2 additions & 2 deletions database_cleanup/models/purge_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _module_data_uninstall(self, modules_to_remove):
continue
if this.model not in self.env:
this.unlink()
return super(IrModelData, self)._module_data_uninstall(modules_to_remove)
return super()._module_data_uninstall(modules_to_remove)


class CleanupPurgeLineModule(models.TransientModel):
Expand All @@ -53,7 +53,7 @@ def purge(self):
modules.filtered(
lambda x: x.state not in ("uninstallable", "uninstalled")
).button_immediate_uninstall()
modules.refresh()
modules.env.invalidate_all()
modules.unlink()
return self.write({"purged": True})

Expand Down
6 changes: 3 additions & 3 deletions database_cleanup/models/purge_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create(self, values):
# make sure the user trying this is actually supposed to do it
if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id:
raise AccessDenied
return super(CleanupPurgeLine, self).create(values)
return super().create(values)


class PurgeWizard(models.AbstractModel):
Expand All @@ -41,7 +41,7 @@ class PurgeWizard(models.AbstractModel):

@api.model
def default_get(self, fields_list):
res = super(PurgeWizard, self).default_get(fields_list)
res = super().default_get(fields_list)
if "purge_line_ids" in fields_list:
res["purge_line_ids"] = self.find()
return res
Expand Down Expand Up @@ -85,6 +85,6 @@ def create(self, values):
# make sure the user trying this is actually supposed to do it
if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id:
raise AccessDenied
return super(PurgeWizard, self).create(values)
return super().create(values)

purge_line_ids = fields.One2many("cleanup.purge.line", "wizard_id")
2 changes: 1 addition & 1 deletion database_cleanup/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.modules.registry import Registry
from odoo.tests import TransactionCase
from odoo.tests.common import TransactionCase


class Common(TransactionCase):
Expand Down

0 comments on commit e937f03

Please sign in to comment.