Skip to content
Snippets Groups Projects
Commit 0121876e authored by Benjami's avatar Benjami
Browse files

Add admin into communiy energy

parent 96b81b70
No related branches found
No related tags found
No related merge requests found
......@@ -128,6 +128,39 @@ class ResCompany(models.Model):
admins_user_ids.append(role_line.user_id.id)
return any([user in admins_user_ids for user in company_user_ids])
def add_ce_admin(self, user):
if self.hierarchy_level != COMMUNITY_HIERARCHY:
raise UserError(_("Only a CE can have CE admins"))
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?
])
if current_role and len(current_role) > 1:
raise UserError(_("Error: This user have multiple roles for this company"))
if current_role and len(current_role.company_ids) > 1:
raise UserError(_("Error: One role line can't have multiple users"))
if current_role and current_role.role.code != "role_ce_member":
raise UserError(_("Error: You can't remove {} role").format(current_role.role.code))
if current_role:
current_role.write({"role_id": role})
else:
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)
})
def get_ce_members(self, domain_key="in_kc_and_active"):
domains_dict = {
"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