From cde4800a3421fda1fc9836b33559dcf88b212264 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 28 Aug 2015 17:51:24 +0200 Subject: [PATCH 1/2] [ADD] allow to clean up menus --- database_cleanup/__openerp__.py | 1 + database_cleanup/model/__init__.py | 1 + database_cleanup/model/purge_menus.py | 81 ++++++++++++++++++++++++++ database_cleanup/model/purge_wizard.py | 13 +++++ database_cleanup/view/menu.xml | 7 +++ database_cleanup/view/purge_menus.xml | 33 +++++++++++ 6 files changed, 136 insertions(+) create mode 100644 database_cleanup/model/purge_menus.py create mode 100644 database_cleanup/view/purge_menus.xml diff --git a/database_cleanup/__openerp__.py b/database_cleanup/__openerp__.py index a164e6043..9b6df9e77 100644 --- a/database_cleanup/__openerp__.py +++ b/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', diff --git a/database_cleanup/model/__init__.py b/database_cleanup/model/__init__.py index 77faf891c..004a4e3bb 100644 --- a/database_cleanup/model/__init__.py +++ b/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 diff --git a/database_cleanup/model/purge_menus.py b/database_cleanup/model/purge_menus.py new file mode 100644 index 000000000..ee8b2d8c4 --- /dev/null +++ b/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 (). +# +# 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 . +# +############################################################################## +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}) + + +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'), + } diff --git a/database_cleanup/model/purge_wizard.py b/database_cleanup/model/purge_wizard.py index 8629eb0b3..ae9430b90 100644 --- a/database_cleanup/model/purge_wizard.py +++ b/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), } diff --git a/database_cleanup/view/menu.xml b/database_cleanup/view/menu.xml index 9d770ea03..82577bdc9 100644 --- a/database_cleanup/view/menu.xml +++ b/database_cleanup/view/menu.xml @@ -44,5 +44,12 @@ + + Purge obsolete menu entries + + + + + diff --git a/database_cleanup/view/purge_menus.xml b/database_cleanup/view/purge_menus.xml new file mode 100644 index 000000000..fc9a5a2cc --- /dev/null +++ b/database_cleanup/view/purge_menus.xml @@ -0,0 +1,33 @@ + + + + + Form view for purge menus wizard + cleanup.purge.wizard.menu + +
+

+ +

+