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.

24 lines
751 B

  1. # Copyright 2020 Akretion (http://www.akretion.com).
  2. # @author Sébastien BEAU <sebastien.beau@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import _, models
  5. from odoo.exceptions import UserError
  6. class Base(models.AbstractModel):
  7. _inherit = "base"
  8. def sudo_tech(self, raise_if_missing=False):
  9. self_sudoer = self
  10. tech_user = self.env.user.company_id.user_tech_id
  11. if tech_user:
  12. self_sudoer = self.sudo(tech_user.id)
  13. elif raise_if_missing:
  14. raise UserError(
  15. _("The technical user is missing in the company {}").format(
  16. self.env.user.company_id.name
  17. )
  18. )
  19. return self_sudoer