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.

23 lines
854 B

  1. # Copyright (C) 2021 Open Source Integrators
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import models
  4. from odoo.http import request
  5. class IrHttp(models.AbstractModel):
  6. _inherit = "ir.http"
  7. def session_info(self):
  8. """
  9. Based on the selected companies (cids),
  10. calculate the roles to enable.
  11. A role should be enabled only when it applies to all selected companies.
  12. """
  13. result = super(IrHttp, self).session_info()
  14. if self.env.user.role_line_ids:
  15. cids_str = request.httprequest.cookies.get("cids", str(self.env.company.id))
  16. cids = [int(cid) for cid in cids_str.split(",")]
  17. # The first element of cids is the currently selected company
  18. self.env.user.set_groups_from_roles(company_id=cids[0])
  19. return result