Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions operating_unit/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# - Jordi Ballester Alomar
# Copyright 2015-TODAY Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models


Expand All @@ -13,18 +14,20 @@ class ResUsers(models.Model):
def operating_unit_default_get(self, uid2=False):
if not uid2:
uid2 = self.env.user.id
user = self.env["res.users"].browse(uid2)
# Grant sudo for the user to avoid access rights issues while checking
# access to operating units.
user = self.env["res.users"].sudo().browse(uid2)
# check if the company of the default OU is active
if user.default_operating_unit_id.sudo().company_id in self.env.companies:
if user.default_operating_unit_id.company_id in self.env.companies:
return user.default_operating_unit_id
else:
# find an OU of the main active company
for ou in user.operating_unit_ids:
if ou.sudo().company_id in self.env.company:
if ou.company_id == self.env.company:
return ou
# find an OU of any active company
for ou in user.operating_unit_ids:
if ou.sudo().company_id in self.env.companies:
if ou.company_id in self.env.companies:
return ou
return False

Expand Down