[FIX] really uninstall modules and avoid a crash on cached data
[FIX] don't try to uninstall uninstalled modules [DEL] weird code [FIX] actually cleanup where we canpull/2684/head
parent
73cb3aa9d2
commit
8d03304f64
|
@ -10,11 +10,9 @@ class IrModel(models.Model):
|
||||||
_inherit = 'ir.model'
|
_inherit = 'ir.model'
|
||||||
|
|
||||||
def _drop_table(self):
|
def _drop_table(self):
|
||||||
# Allow to skip this step during model unlink
|
"""this function crashes for undefined models"""
|
||||||
# The super method crashes if the model cannot be instantiated
|
existing_model_ids = self.filtered(lambda x: x.model in self.env)
|
||||||
if self.env.context.get('no_drop_table'):
|
return super(IrModel, existing_model_ids)._drop_table()
|
||||||
return True
|
|
||||||
return super(IrModel, self)._drop_table()
|
|
||||||
|
|
||||||
@api.depends()
|
@api.depends()
|
||||||
def _inherited_models(self):
|
def _inherited_models(self):
|
||||||
|
@ -28,11 +26,9 @@ class IrModelFields(models.Model):
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _prepare_update(self):
|
def _prepare_update(self):
|
||||||
# Allow to skip this step during model unlink
|
"""this function crashes for undefined models"""
|
||||||
# The super method crashes if the model cannot be instantiated
|
existing = self.filtered(lambda x: x.model in self.env)
|
||||||
if self.env.context.get('no_prepare_update'):
|
return super(IrModelFields, existing)._prepare_update()
|
||||||
return True
|
|
||||||
return super(IrModelFields, self)._prepare_update()
|
|
||||||
|
|
||||||
|
|
||||||
class CleanupPurgeLineModel(models.TransientModel):
|
class CleanupPurgeLineModel(models.TransientModel):
|
||||||
|
@ -50,9 +46,7 @@ class CleanupPurgeLineModel(models.TransientModel):
|
||||||
"""
|
"""
|
||||||
context_flags = {
|
context_flags = {
|
||||||
MODULE_UNINSTALL_FLAG: True,
|
MODULE_UNINSTALL_FLAG: True,
|
||||||
'no_drop_table': True,
|
|
||||||
'purge': True,
|
'purge': True,
|
||||||
'no_prepare_update': True,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self:
|
if self:
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.modules.registry import RegistryManager
|
|
||||||
from odoo.modules.module import get_module_path
|
from odoo.modules.module import get_module_path
|
||||||
from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
|
from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
|
||||||
|
|
||||||
|
@ -41,25 +40,19 @@ class CleanupPurgeLineModule(models.TransientModel):
|
||||||
Uninstall modules upon manual confirmation, then reload
|
Uninstall modules upon manual confirmation, then reload
|
||||||
the database.
|
the database.
|
||||||
"""
|
"""
|
||||||
if self:
|
module_names = self.filtered(lambda x: not x.purged).mapped('name')
|
||||||
objs = self
|
|
||||||
else:
|
|
||||||
objs = self.env['cleanup.purge.line.module']\
|
|
||||||
.browse(self._context.get('active_ids'))
|
|
||||||
module_names = objs.filtered(lambda x: not x.purged).mapped('name')
|
|
||||||
modules = self.env['ir.module.module'].search([
|
modules = self.env['ir.module.module'].search([
|
||||||
('name', 'in', module_names)
|
('name', 'in', module_names)
|
||||||
])
|
])
|
||||||
if not modules:
|
if not modules:
|
||||||
return True
|
return True
|
||||||
self.logger.info('Purging modules %s', ', '.join(module_names))
|
self.logger.info('Purging modules %s', ', '.join(module_names))
|
||||||
modules.button_uninstall()
|
modules.filtered(
|
||||||
# we need this commit because reloading the registry would roll back
|
lambda x: x.state not in ('uninstallable', 'uninstalled')
|
||||||
# our changes
|
).button_immediate_uninstall()
|
||||||
self.env.cr.commit() # pylint: disable=invalid-commit
|
modules.refresh()
|
||||||
RegistryManager.new(self.env.cr.dbname, update_module=True)
|
|
||||||
modules.unlink()
|
modules.unlink()
|
||||||
return objs.write({'purged': True})
|
return self.write({'purged': True})
|
||||||
|
|
||||||
|
|
||||||
class CleanupPurgeWizardModule(models.TransientModel):
|
class CleanupPurgeWizardModule(models.TransientModel):
|
||||||
|
|
Loading…
Reference in New Issue