Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions database_cleanup/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -50,6 +50,7 @@ Contributors

* Stefan Rijnhart <stefan@opener.amsterdam>
* Holger Brunn <hbrunn@therp.nl>
* Miku Laitinen <miku@avoin.systems>

Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

Expand Down
7 changes: 4 additions & 3 deletions database_cleanup/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# © 2017 Avoin.Systems <https://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',
Expand All @@ -18,5 +19,5 @@
'views/purge_data.xml',
'views/menu.xml',
],
'installable': False,
'installable': True,
}
11 changes: 5 additions & 6 deletions database_cleanup/models/purge_columns.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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


Expand Down Expand Up @@ -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, [])
Expand Down
4 changes: 2 additions & 2 deletions database_cleanup/models/purge_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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


Expand Down
4 changes: 2 additions & 2 deletions database_cleanup/models/purge_menus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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):
Expand Down
21 changes: 6 additions & 15 deletions database_cleanup/models/purge_models.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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
if self.env.context.get('no_drop_table'):
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'
Expand Down
10 changes: 5 additions & 5 deletions database_cleanup/models/purge_modules.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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):
Expand Down
10 changes: 4 additions & 6 deletions database_cleanup/models/purge_tables.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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


Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions database_cleanup/models/purge_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# © 2014-2016 Therp BV <http://therp.nl>
# 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):
Expand Down
6 changes: 3 additions & 3 deletions database_cleanup/tests/test_database_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# © 2016 Therp BV <http://therp.nl>
# 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):
Expand Down
108 changes: 53 additions & 55 deletions database_cleanup/views/menu.xml
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record model="ir.ui.menu" id="menu_database_cleanup">
<field name="name">Database cleanup</field>
<field name="sequence" eval="10" />
<!-- attach to Settings -> Technical -->
<field name="parent_id" ref="base.menu_custom"/>
<field name="groups_id" eval="[(6,0, [ref('base.group_erp_manager')])]"/>
</record>

<record model="ir.ui.menu" id="menu_purge_modules">
<field name="name">Purge obsolete modules</field>
<field name="sequence" eval="10" />
<field name="action" ref="action_purge_modules" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_models">
<field name="name">Purge obsolete models</field>
<field name="sequence" eval="20" />
<field name="action" ref="action_purge_models" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_columns">
<field name="name">Purge obsolete columns</field>
<field name="sequence" eval="30" />
<field name="action" ref="action_purge_columns" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_tables">
<field name="name">Purge obsolete tables</field>
<field name="sequence" eval="40" />
<field name="action" ref="action_purge_tables" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_data">
<field name="name">Purge obsolete data entries</field>
<field name="sequence" eval="50" />
<field name="action" ref="action_purge_data" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_menus">
<field name="name">Purge obsolete menu entries</field>
<field name="sequence" eval="60" />
<field name="action" ref="action_purge_menus" />
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

</data>
</openerp>
<odoo>

<record model="ir.ui.menu" id="menu_database_cleanup">
<field name="name">Database cleanup</field>
<field name="sequence" eval="10"/>
<!-- attach to Settings -> Technical -->
<field name="parent_id" ref="base.menu_custom"/>
<field name="groups_id" eval="[(6,0, [ref('base.group_erp_manager')])]"/>
</record>

<record model="ir.ui.menu" id="menu_purge_modules">
<field name="name">Purge obsolete modules</field>
<field name="sequence" eval="10"/>
<field name="action" ref="action_purge_modules"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_models">
<field name="name">Purge obsolete models</field>
<field name="sequence" eval="20"/>
<field name="action" ref="action_purge_models"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_columns">
<field name="name">Purge obsolete columns</field>
<field name="sequence" eval="30"/>
<field name="action" ref="action_purge_columns"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_tables">
<field name="name">Purge obsolete tables</field>
<field name="sequence" eval="40"/>
<field name="action" ref="action_purge_tables"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_data">
<field name="name">Purge obsolete data entries</field>
<field name="sequence" eval="50"/>
<field name="action" ref="action_purge_data"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

<record model="ir.ui.menu" id="menu_purge_menus">
<field name="name">Purge obsolete menu entries</field>
<field name="sequence" eval="60"/>
<field name="action" ref="action_purge_menus"/>
<field name="parent_id" ref="menu_database_cleanup"/>
</record>

</odoo>
Loading