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