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.

35 lines
1.1 KiB

  1. # Copyright 2021 Quartile Limited
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  3. from odoo import api, models, tools
  4. from odoo.exceptions import AccessError
  5. from odoo.tools.translate import _
  6. class IrModelAccess(models.Model):
  7. _inherit = "ir.model.access"
  8. @api.model
  9. @tools.ormcache_context(
  10. "self._uid", "model", "mode", "raise_exception", keys=("lang",)
  11. )
  12. def check(self, model, mode="read", raise_exception=True):
  13. res = super(IrModelAccess, self).check(model, mode, raise_exception)
  14. if self._uid == 1:
  15. return True
  16. self._cr.execute(
  17. "SELECT restrict_update FROM ir_model WHERE model = %s", (model,)
  18. )
  19. query_res = self._cr.dictfetchall()[0]
  20. if (
  21. query_res["restrict_update"]
  22. and mode != "read"
  23. and not self.env.user.unrestrict_model_update
  24. ):
  25. if raise_exception:
  26. raise AccessError(
  27. _("You are only allowed to read this record. (%s - %s)")
  28. % (model, mode)
  29. )
  30. return False
  31. return res