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.

37 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2004-today Odoo SA (<http://www.odoo.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import models, fields, api
  5. class WebShortcut(models.Model):
  6. _name = 'web.shortcut'
  7. name = fields.Char('Shortcut Name', size=64)
  8. menu_id = fields.Many2one('ir.ui.menu', ondelete='cascade')
  9. user_id = fields.Many2one('res.users', 'User Ref.', required=True,
  10. ondelete='cascade', select=True,
  11. default=lambda obj, cr, uid, context: uid)
  12. _sql_constraints = [
  13. ('shortcut_unique', 'unique(menu_id,user_id)',
  14. 'Shortcut for this menu already exists!'),
  15. ]
  16. @api.model
  17. def get_user_shortcuts(self):
  18. shortcuts = self.search([('user_id', '=', self.env.user.id)])
  19. res = []
  20. for shortcut in shortcuts.filtered('menu_id'):
  21. _name = shortcut.menu_id.name_get()
  22. _name = _name[0][1] if len(_name) else ''
  23. _id = shortcut.menu_id.id
  24. res.append(
  25. {
  26. 'id': shortcut.id,
  27. 'name': _name,
  28. 'menu_id': (_id, _name)
  29. }
  30. )
  31. return res