Browse Source

Better removal of menus

pull/59/head
Andrea 8 years ago
parent
commit
293e4f7c59
  1. 5
      bi_view_editor/models/bve_view.py
  2. 9
      bi_view_editor/wizard/wizard_ir_model_menu_create.py

5
bi_view_editor/models/bve_view.py

@ -73,11 +73,13 @@ class BveView(models.Model):
def action_reset(self): def action_reset(self):
self.ensure_one() self.ensure_one()
has_menus = False
if self.action_id: if self.action_id:
action = 'ir.actions.act_window,%d' % (self.action_id.id,) action = 'ir.actions.act_window,%d' % (self.action_id.id,)
menus = self.env['ir.ui.menu'].sudo().search( menus = self.env['ir.ui.menu'].sudo().search(
[('action', '=', action)] [('action', '=', action)]
) )
has_menus = True if menus else False
menus.sudo().unlink() menus.sudo().unlink()
if self.action_id.view_id: if self.action_id.view_id:
@ -94,6 +96,9 @@ class BveView(models.Model):
self.state = 'draft' self.state = 'draft'
if has_menus:
return {'type': 'ir.actions.client', 'tag': 'reload'}
@api.multi @api.multi
def _create_view_arch(self): def _create_view_arch(self):
self.ensure_one() self.ensure_one()

9
bi_view_editor/wizard/wizard_ir_model_menu_create.py

@ -14,11 +14,18 @@ class WizardModelMenuCreate(models.TransientModel):
self.ensure_one() self.ensure_one()
active_id = self._context.get('active_id') active_id = self._context.get('active_id')
bve_view = self.env['bve.view'].browse(active_id) bve_view = self.env['bve.view'].browse(active_id)
self.env['ir.ui.menu'].create({
menu = self.env['ir.ui.menu'].create({
'name': self.name, 'name': self.name,
'parent_id': self.menu_id.id, 'parent_id': self.menu_id.id,
'action': 'ir.actions.act_window,%d' % (bve_view.action_id,) 'action': 'ir.actions.act_window,%d' % (bve_view.action_id,)
}) })
self.env['ir.model.data'].create({
'name': bve_view.name + ', id=' + str(menu.id),
'noupdate': True,
'module': 'bi_view_editor',
'model': 'ir.ui.menu',
'res_id': menu.id,
})
return {'type': 'ir.actions.client', 'tag': 'reload'} return {'type': 'ir.actions.client', 'tag': 'reload'}
return super(WizardModelMenuCreate, self).menu_create() return super(WizardModelMenuCreate, self).menu_create()

Loading…
Cancel
Save