Browse Source

[ADD] allow to clean up menus

pull/1408/head
Holger Brunn 9 years ago
committed by Pedro M. Baeza
parent
commit
40530a96bd
  1. 1
      database_cleanup/__openerp__.py
  2. 1
      database_cleanup/model/__init__.py
  3. 81
      database_cleanup/model/purge_menus.py
  4. 13
      database_cleanup/model/purge_wizard.py
  5. 7
      database_cleanup/view/menu.xml
  6. 33
      database_cleanup/view/purge_menus.xml

1
database_cleanup/__openerp__.py

@ -27,6 +27,7 @@
'license': 'AGPL-3',
'category': 'Tools',
'data': [
'view/purge_menus.xml',
'view/purge_modules.xml',
'view/purge_models.xml',
'view/purge_columns.xml',

1
database_cleanup/model/__init__.py

@ -4,3 +4,4 @@ from . import purge_models
from . import purge_columns
from . import purge_tables
from . import purge_data
from . import purge_menus

81
database_cleanup/model/purge_menus.py

@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
from openerp.tools.translate import _
class CleanupPurgeLineMenu(orm.TransientModel):
_inherit = 'cleanup.purge.line'
_name = 'cleanup.purge.line.menu'
_columns = {
'wizard_id': fields.many2one(
'cleanup.purge.wizard.menu', 'Purge Wizard', readonly=True),
'menu_id': fields.many2one('ir.ui.menu', 'Menu entry'),
}
def purge(self, cr, uid, ids, context=None):
self.pool['ir.ui.menu'].unlink(
cr, uid,
[this.menu_id.id for this in self.browse(cr, uid, ids,
context=context)],
context=context)
return self.write(cr, uid, ids, {'purged': True}, context=context)
class CleanupPurgeWizardMenu(orm.TransientModel):
_inherit = 'cleanup.purge.wizard'
_name = 'cleanup.purge.wizard.menu'
def default_get(self, cr, uid, fields, context=None):
res = super(CleanupPurgeWizardMenu, self).default_get(
cr, uid, fields, context=context)
if 'name' in fields:
res['name'] = _('Purge menus')
return res
def find(self, cr, uid, context=None):
"""
Search for models that cannot be instantiated.
"""
res = []
for menu in self.pool['ir.ui.menu'].browse(
cr, uid, self.pool['ir.ui.menu'].search(
cr, uid, [], context=dict(
context or {}, active_test=False))):
if not menu.action or menu.action.type != 'ir.actions.act_window':
continue
if not self.pool.get(menu.action.res_model):
res.append((0, 0, {
'name': menu.complete_name,
'menu_id': menu.id,
}))
if not res:
raise orm.except_orm(
_('Nothing to do'),
_('No dangling menu entries found'))
return res
_columns = {
'purge_line_ids': fields.one2many(
'cleanup.purge.line.menu',
'wizard_id', 'Menus to purge'),
}

13
database_cleanup/model/purge_wizard.py

@ -60,6 +60,19 @@ class PurgeWizard(orm.AbstractModel):
context=context)
return True
def get_wizard_action(self, cr, uid, context=None):
wizard_id = self.create(cr, uid, {}, context=context)
return {
'type': 'ir.actions.act_window',
'views': [(False, 'form')],
'res_model': self._name,
'res_id': wizard_id,
'flags': {
'action_buttons': False,
'sidebar': False,
},
}
_columns = {
'name': fields.char('Name', size=64, readonly=True),
}

7
database_cleanup/view/menu.xml

@ -44,5 +44,12 @@
<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>

33
database_cleanup/view/purge_menus.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="purge_menus_view" model="ir.ui.view">
<field name="name">Form view for purge menus wizard</field>
<field name="model">cleanup.purge.wizard.menu</field>
<field name="arch" type="xml">
<form>
<h1>
<field name="name"/>
</h1>
<button type="object" name="purge_all" string="Purge all menus" />
<field name="purge_line_ids">
<tree>
<field name="name" />
<field name="purged" invisible="0" />
<button type="object" name="purge"
icon="gtk-cancel" string="Purge this model"
attrs="{'invisible': [('purged', '=', True)]}"/>
</tree>
</field>
</form>
</field>
</record>
<record id="action_purge_menus" model="ir.actions.server">
<field name="name">Purge menus</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_menu" />
<field name="code">action = self.get_wizard_action(cr, uid, context=context)</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save