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.

59 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Adrien Peiffer
  5. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  6. # All Rights Reserved
  7. #
  8. # WARNING: This program as such is intended to be used by professional
  9. # programmers who take the whole responsibility of assessing all potential
  10. # consequences resulting from its eventual inadequacies and bugs.
  11. # End users who are looking for a ready-to-use solution with commercial
  12. # guarantees and support are strongly advised to contact a Free Software
  13. # Service Company.
  14. #
  15. # This program is free software: you can redistribute it and/or modify
  16. # it under the terms of the GNU Affero General Public License as
  17. # published by the Free Software Foundation, either version 3 of the
  18. # License, or (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU Affero General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU Affero General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. #
  28. #
  29. from openerp import models, fields, api
  30. class web_shortcut(models.Model):
  31. _name = 'web.shortcut'
  32. name = fields.Char('Shortcut Name', size=64)
  33. menu_id = fields.Many2one('ir.ui.menu')
  34. user_id = fields.Many2one('res.users', 'User Ref.', required=True,
  35. ondelete='cascade', select=True,
  36. default=lambda obj, cr, uid, context: uid)
  37. _sql_constraints = [
  38. ('shortcut_unique', 'unique(menu_id,user_id)',
  39. 'Shortcut for this menu already exists!'),
  40. ]
  41. @api.model
  42. def get_user_shortcuts(self, user_id):
  43. shortcuts = self.search([('user_id', '=', user_id)])
  44. results = shortcuts.read(['menu_id'])
  45. ir_ui_menu_obj = self.env['ir.ui.menu']
  46. menus = ir_ui_menu_obj.search([('id', 'in', [x['menu_id'][0]
  47. for x in results])])
  48. name_map = dict(menus.name_get())
  49. # Make sure to return only shortcuts pointing to existing menu items.
  50. filtered_results = filter(lambda result: result['menu_id'][0] in
  51. name_map, results)
  52. for result in filtered_results:
  53. result.update(name=name_map[result['menu_id'][0]])
  54. return filtered_results