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.2 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. users = self.env.ref('base.group_no_one').users
  23. for user in self:
  24. user.show_technical_features = user in users
  25. @api.multi
  26. @api.depends('groups_id')
  27. def get_technical_features(self):
  28. """ Map user membership to boolean field value """
  29. users = self.env.ref(
  30. 'base_technical_features.group_technical_features').users
  31. for user in self:
  32. user.technical_features = user in users
  33. @api.multi
  34. def set_technical_features(self):
  35. """ Map boolean field value to group membership, but checking
  36. access """
  37. group = self.env.ref(
  38. 'base_technical_features.group_technical_features')
  39. for user in self:
  40. if self.env.ref('base.group_no_one') not in user.groups_id:
  41. raise AccessError(
  42. _('The user does not have access to technical '
  43. 'features.'))
  44. if user.technical_features:
  45. self.sudo().write({'groups_id': [(4, group.id)]})
  46. else:
  47. self.sudo().write({'groups_id': [(3, group.id)]})
  48. def __init__(self, pool, cr):
  49. super(ResUsers, self).__init__(pool, cr)
  50. self.SELF_READABLE_FIELDS += [
  51. 'technical_features', 'show_technical_features']
  52. self.SELF_WRITEABLE_FIELDS.append('technical_features')