Skip to content
Snippets Groups Projects
Commit 9f48d768 authored by Benjami's avatar Benjami
Browse files

Add admin into communiy energy

parent d1d7cfc4
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !142. Comments created here will be created in the context of that merge request.
......@@ -125,6 +125,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