Skip to content
Snippets Groups Projects
Commit cb7a25b3 authored by Benjami's avatar Benjami Committed by konykon
Browse files

Fix relation assignment between users and companies

parent 6c3a9515
No related branches found
No related tags found
3 merge requests!239Draft: [REL] energy_communities: dependency energy_selfconsumption bump to,!227[REL] Release 16/10/23,!142Feature/assign ce admin
......@@ -167,16 +167,16 @@ class ResCompany(models.Model):
return admins
def add_ce_admin(self, user):
if self.hierarchy_level != COMMUNITY_HIERARCHY:
if self.hierarchy_level != 'community':
raise UserError(_("Only a CE can have CE admins"))
role = self.env["res.users.role"].sudo().search([{
role = self.env["res.users.role"].sudo().search([(
"code", "=", "role_ce_admin"
}])
)])
current_role = self.env["res.users.role.line"].sudo().search([
("user_id", "=", user.id),
("active", "=", True),
("allowed_company_ids", "=", self.id) # It's M2M, = is okey?
("company_id", "=", self.id) # It's M2M, = is okey?
])
if current_role and len(current_role) > 1:
raise UserError(_("Error: This user have multiple roles for this company"))
......@@ -188,15 +188,15 @@ class ResCompany(models.Model):
if current_role:
current_role.write({"role_id": role})
else:
user = self.env["res.users"].sudo().browse(user.id)
user.write({
"company_ids": [(4, self.id)]
})
self.env["res.users.role.line"].sudo().create({
"user_id": user.id,
"active": True,
"role_id": role,
"community_ids": (6, 0, self.id),
})
user = self.env["res.users"].sudo().browse(user.id)
user.write({
"community_ids": (6, 0, self.id)
"role_id": role.id,
"company_id": self.id,
})
def get_ce_members(self, domain_key="in_kc_and_active"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment