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.

57 lines
2.1 KiB

  1. # coding: utf-8
  2. # © 2016 Opener B.V. (<https://opener.am>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, models
  5. from openerp.exceptions import AccessError
  6. from openerp.tools.translate import _
  7. class ResUsers(models.Model):
  8. _inherit = 'res.users'
  9. technical_features = fields.Boolean(
  10. compute='get_technical_features',
  11. inverse='set_technical_features')
  12. show_technical_features = fields.Boolean(
  13. string='Show field Technical Features',
  14. compute='get_show_technical_features',
  15. help=('Whether to display the technical features field in the user '
  16. 'preferences.'))
  17. @api.multi
  18. @api.depends('groups_id')
  19. def get_show_technical_features(self):
  20. """ Only display the technical features checkbox in the user
  21. preferences if the user has access to them """
  22. for user in self:
  23. user.show_technical_features = user.has_group('base.group_no_one')
  24. @api.multi
  25. @api.depends('groups_id')
  26. def get_technical_features(self):
  27. """ Map user membership to boolean field value """
  28. for user in self:
  29. user.technical_features = user.has_group(
  30. 'base_technical_features.group_technical_features')
  31. @api.multi
  32. def set_technical_features(self):
  33. """ Map boolean field value to group membership, but checking
  34. access """
  35. group = self.env.ref(
  36. 'base_technical_features.group_technical_features')
  37. for user in self:
  38. if self.env.ref('base.group_no_one') not in user.groups_id:
  39. raise AccessError(
  40. _('The user does not have access to technical '
  41. 'features.'))
  42. if user.technical_features:
  43. self.sudo().write({'groups_id': [(4, group.id)]})
  44. else:
  45. self.sudo().write({'groups_id': [(3, group.id)]})
  46. def __init__(self, pool, cr):
  47. super(ResUsers, self).__init__(pool, cr)
  48. self.SELF_READABLE_FIELDS += [
  49. 'technical_features', 'show_technical_features']
  50. self.SELF_WRITEABLE_FIELDS.append('technical_features')