Holger Brunn
9 years ago
No known key found for this signature in database
GPG Key ID: 1C9760FECA3AE18
6 changed files with 136 additions and 0 deletions
-
1database_cleanup/__openerp__.py
-
1database_cleanup/model/__init__.py
-
81database_cleanup/model/purge_menus.py
-
13database_cleanup/model/purge_wizard.py
-
7database_cleanup/view/menu.xml
-
33database_cleanup/view/purge_menus.xml
@ -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'), |
||||
|
} |
@ -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> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue