You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-today OpenERP SA (<http://www.openerp.com>)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api
  22. class WebShortcut(models.Model):
  23. _name = 'web.shortcut'
  24. name = fields.Char('Shortcut Name', size=64)
  25. menu_id = fields.Many2one('ir.ui.menu', ondelete='cascade')
  26. user_id = fields.Many2one('res.users', 'User Ref.', required=True,
  27. ondelete='cascade', select=True,
  28. default=lambda obj, cr, uid, context: uid)
  29. _sql_constraints = [
  30. ('shortcut_unique', 'unique(menu_id,user_id)',
  31. 'Shortcut for this menu already exists!'),
  32. ]
  33. @api.model
  34. def get_user_shortcuts(self, user_id):
  35. shortcuts = self.search([('user_id', '=', user_id)])
  36. res = []
  37. for shortcut in shortcuts.filtered('menu_id'):
  38. _name = shortcut.menu_id.name_get()
  39. _name = _name[0][1] if len(_name) else ''
  40. _id = shortcut.menu_id.id
  41. res.append(
  42. {
  43. 'id': shortcut.id,
  44. 'name': _name,
  45. 'menu_id': (_id, _name)
  46. }
  47. )
  48. return res
  49. class IrUiView(models.Model):
  50. _inherit = 'ir.ui.menu'
  51. @api.multi
  52. def unlink(self):
  53. res = super(IrUiView, self).unlink()
  54. shortcuts = self.env['web.shortcut'].search([('menu_id', '=', False)])
  55. for shortcut in shortcuts:
  56. shortcut.unlink()
  57. return res