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.

50 lines
1.9 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 odoo 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', index=True,
  11. default=lambda self: self.env.user.id)
  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. trans = self.env['ir.translation']
  21. for shortcut in shortcuts.filtered('menu_id'):
  22. name_translated = trans._get_source('ir.ui.menu,name', 'model',
  23. self.env.user.lang,
  24. shortcut.menu_id.name,
  25. shortcut.menu_id.id)
  26. current = shortcut.menu_id
  27. while current.parent_id:
  28. current = current.parent_id
  29. name_translated = ' / '.join((
  30. trans._get_source('ir.ui.menu,name', 'model',
  31. self.env.user.lang,
  32. current.name, current.id),
  33. name_translated))
  34. _name = shortcut.menu_id.name_get()
  35. _name = _name[0][1] if len(_name) else ''
  36. _id = shortcut.menu_id.id
  37. res.append(
  38. {
  39. 'id': shortcut.id,
  40. 'name': name_translated,
  41. 'menu_id': (_id, _name)
  42. }
  43. )
  44. return res