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.

47 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from lxml import etree
  5. from odoo import _, api, fields, models
  6. from odoo.exceptions import AccessError
  7. from .ir_config_parameter import THRESHOLD_HIDE
  8. from .res_groups import THRESHOLD_MANAGER
  9. class ResCompany(models.Model):
  10. _inherit = 'res.company'
  11. max_users = fields.Integer(
  12. 'Maximum Number of users allowed for this company',
  13. )
  14. @api.model
  15. def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
  16. submenu=False):
  17. """ Hide Max User Field when the env var to hide the field is set """
  18. res = super(ResCompany, self).fields_view_get(
  19. view_id, view_type, toolbar, submenu
  20. )
  21. if THRESHOLD_HIDE:
  22. doc = etree.XML(res['arch'])
  23. for node in doc.xpath("//field[@name='max_users']"):
  24. node.getparent().remove(node)
  25. res['arch'] = etree.tostring(doc, pretty_print=True)
  26. return res
  27. @api.multi
  28. def write(self, vals):
  29. """
  30. Override to disallow manipulation of the user threshold parameter
  31. when the user does not have the right access
  32. """
  33. is_manager = self.env.user.has_group(THRESHOLD_MANAGER)
  34. if vals.get('max_users') and not is_manager:
  35. raise AccessError(_(
  36. 'You must be a member of the `User Threshold Manager` to set '
  37. 'this parameter'
  38. ))
  39. return super(ResCompany, self).write(vals)