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.

55 lines
2.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Therp BV (<http://therp.nl>)
  6. #
  7. # Code snippets from openobject-server 7.0
  8. # (C) 2004-2012 OpenERP S.A. (<http://openerp.com>)
  9. #
  10. #
  11. # All Rights Reserved
  12. #
  13. # This program is free software: you can redistribute it and/or modify
  14. # it under the terms of the GNU Affero General Public License as
  15. # published by the Free Software Foundation, either version 3 of the
  16. # License, or (at your option) any later version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU Affero General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU Affero General Public License
  24. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. #
  26. ##############################################################################
  27. from openerp.osv.orm import Model
  28. from openerp.osv import fields
  29. from openerp import SUPERUSER_ID
  30. class ir_ui_view(Model):
  31. _inherit = 'ir.ui.view'
  32. _columns = {
  33. 'groups_id': fields.many2many(
  34. 'res.groups', 'ir_ui_view_group_rel', 'view_id', 'group_id',
  35. string='Groups', help="If this field is empty, the view "
  36. "applies to all users. Otherwise, the view applies to the "
  37. "users of those groups only."),
  38. }
  39. def get_inheriting_views_arch(self, cr, uid, view_id, model, context=None):
  40. user_groups = frozenset(self.pool.get('res.users').browse(
  41. cr, SUPERUSER_ID, uid, context).groups_id)
  42. view_ids = [v[1] for v in
  43. super(ir_ui_view, self).get_inheriting_views_arch(
  44. cr, uid, view_id, model, context=context)]
  45. # filter views based on user groups
  46. return [(view.arch, view.id)
  47. for view in self.browse(cr, SUPERUSER_ID, view_ids, context)
  48. if not (view.groups_id and
  49. user_groups.isdisjoint(view.groups_id))]