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.

38 lines
1.4 KiB

  1. # Copyright 2022 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from lxml import etree
  4. from odoo import api, models
  5. from odoo.addons.base.models.ir_ui_view import (
  6. transfer_modifiers_to_node,
  7. transfer_node_to_modifiers,
  8. )
  9. class ResPartner(models.Model):
  10. _inherit = "res.partner"
  11. @api.model
  12. def fields_view_get(
  13. self, view_id=None, view_type="form", toolbar=False, submenu=False
  14. ):
  15. """We define the category_id field read-only if the user does not have
  16. permissions."""
  17. result = super().fields_view_get(view_id, view_type, toolbar, submenu)
  18. category_group = "partner_category_security.group_partner_category_user"
  19. if view_type == "form" and not self.env.user.has_group(category_group):
  20. doc = etree.XML(result["arch"])
  21. nodes = doc.xpath("//field[@name='category_id']")
  22. if nodes:
  23. nodes[0].set("readonly", "1")
  24. nodes[0].set("force_save", "1")
  25. modifiers = {}
  26. transfer_node_to_modifiers(nodes[0], modifiers)
  27. transfer_modifiers_to_node(modifiers, nodes[0])
  28. xarch, xfields = self.env["ir.ui.view"].postprocess_and_fields(
  29. doc, self._name
  30. )
  31. result["arch"] = xarch
  32. result["fields"] = xfields
  33. return result