diff --git a/database_cleanup/README.rst b/database_cleanup/README.rst index 42222ae545c..8da9a752070 100644 --- a/database_cleanup/README.rst +++ b/database_cleanup/README.rst @@ -6,13 +6,13 @@ Database cleanup ================ -Clean your OpenERP database from remnants of modules, models, columns and +Clean your Odoo database from remnants of modules, models, columns and tables left by uninstalled modules (prior to 7.0) or a homebrew database -upgrade to a new major version of OpenERP. +upgrade to a new major version of Odoo. Caution! This module is potentially harmful and can *easily* destroy the integrity of your data. Do not use if you are not entirely comfortable -with the technical details of the OpenERP data model of *all* the modules +with the technical details of the Odoo data model of *all* the modules that have ever been installed on your database, and do not purge any module, model, column or table if you do not know exactly what you are doing. @@ -50,6 +50,7 @@ Contributors * Stefan Rijnhart * Holger Brunn +* Miku Laitinen Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. diff --git a/database_cleanup/__manifest__.py b/database_cleanup/__manifest__.py index 036988cf5cf..9d2e79be524 100644 --- a/database_cleanup/__manifest__.py +++ b/database_cleanup/__manifest__.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV +# © 2017 Avoin.Systems # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Database cleanup', - 'version': '9.0.1.0.0', - 'author': "Therp BV,Odoo Community Association (OCA)", + 'version': '10.0.1.0.0', + 'author': "Therp BV, Avoin.Systems, Odoo Community Association (OCA)", 'depends': ['base'], 'license': 'AGPL-3', 'category': 'Tools', @@ -18,5 +19,5 @@ 'views/purge_data.xml', 'views/menu.xml', ], - 'installable': False, + 'installable': True, } diff --git a/database_cleanup/models/purge_columns.py b/database_cleanup/models/purge_columns.py index 3a3718c214b..c672dd9a762 100644 --- a/database_cleanup/models/purge_columns.py +++ b/database_cleanup/models/purge_columns.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, fields, models -from openerp.exceptions import UserError +from odoo import _, api, fields, models +from odoo.exceptions import UserError from ..identifier_adapter import IdentifierAdapter @@ -73,10 +73,9 @@ def get_orphaned_columns(self, model_pools): columns = list(set([ column for model_pool in model_pools - for column in model_pool._columns - if not (isinstance(model_pool._columns[column], - fields.fields.function) and - not model_pool._columns[column].store) + for column in model_pool._fields + if not (model_pool._fields[column].compute and + not model_pool._fields[column].store) ])) columns += models.MAGIC_COLUMNS columns += self.blacklist.get(model_pools[0]._table, []) diff --git a/database_cleanup/models/purge_data.py b/database_cleanup/models/purge_data.py index 9e1817ff808..1481e7806a6 100644 --- a/database_cleanup/models/purge_data.py +++ b/database_cleanup/models/purge_data.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, fields, models -from openerp.exceptions import UserError +from odoo import _, api, fields, models +from odoo.exceptions import UserError from ..identifier_adapter import IdentifierAdapter diff --git a/database_cleanup/models/purge_menus.py b/database_cleanup/models/purge_menus.py index 02716493365..446ca6993f6 100644 --- a/database_cleanup/models/purge_menus.py +++ b/database_cleanup/models/purge_menus.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, fields, models -from openerp.exceptions import UserError +from odoo import _, api, fields, models +from odoo.exceptions import UserError class CleanupPurgeLineMenu(models.TransientModel): diff --git a/database_cleanup/models/purge_models.py b/database_cleanup/models/purge_models.py index 996cea61d77..f654404e9fd 100644 --- a/database_cleanup/models/purge_models.py +++ b/database_cleanup/models/purge_models.py @@ -1,15 +1,14 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, models, fields -from openerp.exceptions import UserError -from openerp.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG +from odoo import _, api, models, fields +from odoo.exceptions import UserError +from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG class IrModel(models.Model): _inherit = 'ir.model' - @api.multi def _drop_table(self): # Allow to skip this step during model unlink # The super method crashes if the model cannot be instantiated @@ -17,26 +16,18 @@ def _drop_table(self): return True return super(IrModel, self)._drop_table() - @api.multi - def _inherited_models(self, field_name, arg): + @api.depends() + def _inherited_models(self): """this function crashes for undefined models""" result = dict((i, []) for i in self.ids) existing_model_ids = [ this.id for this in self if this.model in self.env ] super_result = super(IrModel, self.browse(existing_model_ids))\ - ._inherited_models(field_name, arg) + ._inherited_models() result.update(super_result) return result - def _register_hook(self, cr): - # patch the function field instead of overwriting it - if self._columns['inherited_model_ids']._fnct !=\ - self._inherited_models.__func__: - self._columns['inherited_model_ids']._fnct =\ - self._inherited_models.__func__ - return super(IrModel, self)._register_hook(cr) - class CleanupPurgeLineModel(models.TransientModel): _inherit = 'cleanup.purge.line' diff --git a/database_cleanup/models/purge_modules.py b/database_cleanup/models/purge_modules.py index 6b20b9a6fee..b5d918c90c6 100644 --- a/database_cleanup/models/purge_modules.py +++ b/database_cleanup/models/purge_modules.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, fields, models -from openerp.exceptions import UserError -from openerp.modules.registry import RegistryManager -from openerp.modules.module import get_module_path -from openerp.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG +from odoo import _, api, fields, models +from odoo.exceptions import UserError +from odoo.modules.registry import RegistryManager +from odoo.modules.module import get_module_path +from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG class IrModelData(models.Model): diff --git a/database_cleanup/models/purge_tables.py b/database_cleanup/models/purge_tables.py index 62503f790a0..af917ca12b2 100644 --- a/database_cleanup/models/purge_tables.py +++ b/database_cleanup/models/purge_tables.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models, _ -from openerp.exceptions import UserError +from odoo import api, fields, models, _ +from odoo.exceptions import UserError from ..identifier_adapter import IdentifierAdapter @@ -85,10 +85,8 @@ def find(self): known_tables.append(model_pool._table) known_tables += [ column._sql_names(model_pool)[0] - for column in model_pool._columns.values() - if (column._type == 'many2many' and - hasattr(column, '_rel')) # unstored function fields of - # type m2m don't have _rel + for column in model_pool._fields.values() + if isinstance(column, fields.Many2many) and column.store ] self.env.cr.execute( diff --git a/database_cleanup/models/purge_wizard.py b/database_cleanup/models/purge_wizard.py index 0e1645adc76..2685f958fb1 100644 --- a/database_cleanup/models/purge_wizard.py +++ b/database_cleanup/models/purge_wizard.py @@ -2,8 +2,8 @@ # © 2014-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging -from openerp import _, api, fields, models -from openerp.exceptions import AccessDenied +from odoo import _, api, fields, models +from odoo.exceptions import AccessDenied class CleanupPurgeLine(models.AbstractModel): diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index 060c9174e96..d00946827b5 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -2,9 +2,9 @@ # © 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from psycopg2 import ProgrammingError -from openerp.modules.registry import RegistryManager -from openerp.tools import config -from openerp.tests.common import TransactionCase +from odoo.modules.registry import RegistryManager +from odoo.tools import config +from odoo.tests.common import TransactionCase class TestDatabaseCleanup(TransactionCase): diff --git a/database_cleanup/views/menu.xml b/database_cleanup/views/menu.xml index 0796f907b07..2b6e5340fdc 100644 --- a/database_cleanup/views/menu.xml +++ b/database_cleanup/views/menu.xml @@ -1,56 +1,54 @@ - - - - - Database cleanup - - - - - - - - Purge obsolete modules - - - - - - - Purge obsolete models - - - - - - - Purge obsolete columns - - - - - - - Purge obsolete tables - - - - - - - Purge obsolete data entries - - - - - - - Purge obsolete menu entries - - - - - - - + + + + Database cleanup + + + + + + + + Purge obsolete modules + + + + + + + Purge obsolete models + + + + + + + Purge obsolete columns + + + + + + + Purge obsolete tables + + + + + + + Purge obsolete data entries + + + + + + + Purge obsolete menu entries + + + + + + diff --git a/database_cleanup/views/purge_columns.xml b/database_cleanup/views/purge_columns.xml index 1264a89072f..58451224529 100644 --- a/database_cleanup/views/purge_columns.xml +++ b/database_cleanup/views/purge_columns.xml @@ -1,50 +1,48 @@ - - - - cleanup.purge.wizard.column - - primary - - - - + + + cleanup.purge.wizard.column + + primary + + + - + + - - Purge columns - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + Purge columns + ir.actions.server + code + + action = env['cleanup.purge.wizard.column'].get_wizard_action() + - - cleanup.purge.line.column - - primary - - - - + + cleanup.purge.line.column + + primary + + + - + + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + - - Purge - action - client_action_multi - cleanup.purge.line.column - - - - + + Purge + action + client_action_multi + cleanup.purge.line.column + + + diff --git a/database_cleanup/views/purge_data.xml b/database_cleanup/views/purge_data.xml index 3f9988be3b2..2ca63b1f098 100644 --- a/database_cleanup/views/purge_data.xml +++ b/database_cleanup/views/purge_data.xml @@ -1,50 +1,48 @@ - - - - cleanup.purge.wizard.data - - primary - - - - + + + cleanup.purge.wizard.data + + primary + + + - + + - - Purge data entries that refer to missing resources - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + Purge data entries that refer to missing resources + ir.actions.server + code + + action = env['cleanup.purge.wizard.data'].get_wizard_action() + - - cleanup.purge.line.data - - primary - - - - + + cleanup.purge.line.data + + primary + + + - + + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + - - Purge - action - client_action_multi - cleanup.purge.line.data - - - - + + Purge + action + client_action_multi + cleanup.purge.line.data + + + diff --git a/database_cleanup/views/purge_menus.xml b/database_cleanup/views/purge_menus.xml index 0bec65143b2..53c5d5c3c16 100644 --- a/database_cleanup/views/purge_menus.xml +++ b/database_cleanup/views/purge_menus.xml @@ -1,47 +1,45 @@ - - - - cleanup.purge.wizard.menu - - primary - - - - + + + cleanup.purge.wizard.menu + + primary + + + + - - Purge menus - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + Purge menus + ir.actions.server + code + + action = env['cleanup.purge.wizard.menu'].get_wizard_action() + - - cleanup.purge.line.menu - - primary - - - - + + cleanup.purge.line.menu + + primary + + + + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + - - Purge - action - client_action_multi - cleanup.purge.line.menu - - + + Purge + action + client_action_multi + cleanup.purge.line.menu + + - - + diff --git a/database_cleanup/views/purge_models.xml b/database_cleanup/views/purge_models.xml index 5b9401bebf8..4cbda7cf1cc 100644 --- a/database_cleanup/views/purge_models.xml +++ b/database_cleanup/views/purge_models.xml @@ -1,47 +1,45 @@ - - - - cleanup.purge.wizard.model - - primary - - - - + + + cleanup.purge.wizard.model + + primary + + + + - - Purge models - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + Purge models + ir.actions.server + code + + action = env['cleanup.purge.wizard.model'].get_wizard_action() + - - cleanup.purge.line.model - - primary - - - - + + cleanup.purge.line.model + + primary + + + + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + - - Purge - action - client_action_multi - cleanup.purge.line.model - - + + Purge + action + client_action_multi + cleanup.purge.line.model + + - - + diff --git a/database_cleanup/views/purge_modules.xml b/database_cleanup/views/purge_modules.xml index f5f6d2c4dc3..da8c645c9a8 100644 --- a/database_cleanup/views/purge_modules.xml +++ b/database_cleanup/views/purge_modules.xml @@ -1,47 +1,45 @@ - - - - cleanup.purge.wizard.module - - primary - - - - + + + cleanup.purge.wizard.module + + primary + + + + - - Purge modules - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + Purge modules + ir.actions.server + code + + action = env['cleanup.purge.wizard.module'].get_wizard_action() + - - cleanup.purge.line.module - - primary - - - - + + cleanup.purge.line.module + + primary + + + + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + - - Purge - action - client_action_multi - cleanup.purge.line.module - - + + Purge + action + client_action_multi + cleanup.purge.line.module + + - - + diff --git a/database_cleanup/views/purge_tables.xml b/database_cleanup/views/purge_tables.xml index 9cf603cb9cc..45acbec5b11 100644 --- a/database_cleanup/views/purge_tables.xml +++ b/database_cleanup/views/purge_tables.xml @@ -1,46 +1,46 @@ - - - - cleanup.purge.wizard.table - - primary - - - - + - - Purge tables - ir.actions.server - code - - action = self.get_wizard_action(cr, uid, context=context) - + + cleanup.purge.wizard.table + + primary + + + + - - cleanup.purge.line.table - - primary - - - - + + Purge tables + ir.actions.server + code + + action = env['cleanup.purge.wizard.table'].get_wizard_action() + - - Purge - ir.actions.server - code - - self.purge(cr, uid, context.get('active_ids', []), context) - + + cleanup.purge.line.table + + primary + + + + - - Purge - action - client_action_multi - cleanup.purge.line.table - - - - + + Purge + ir.actions.server + code + + record.browse(env.context.get('active_ids', [])).purge() + + + + Purge + action + client_action_multi + cleanup.purge.line.table + + + + diff --git a/database_cleanup/views/purge_wizard.xml b/database_cleanup/views/purge_wizard.xml index 40417f3a813..b44929e6a1f 100644 --- a/database_cleanup/views/purge_wizard.xml +++ b/database_cleanup/views/purge_wizard.xml @@ -1,41 +1,41 @@ - - - - cleanup.purge.wizard - -
-
-
- - - - - - -
-
- -
- -
-
- - cleanup.purge.line - - - - -