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

Add admin type depends on hierarchy level

parent f85a9bcf
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.
......@@ -132,27 +132,33 @@ 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])
# TODO: Get admins depends on hierarcy level
def _get_admin_role_name(self):
if self.hierarchy_level == 'community':
return "role_ce_admin"
elif self.hierarchy_level == 'coordinator':
return "role_coordination"
elif self.hierarchy_level == 'instance':
return "role_platform_admin"
def _get_admins(self):
role_name = self._get_admin_role_name()
for rec in self:
role_lines = self.env["res.users.role.line"].sudo().search([
("company_id.id", "=", self.id),
("active", "=", True),
("role_id.code", "=", "role_ce_admin")
("role_id.code", "=", role_name)
])
rec.admins = role_lines.mapped("user_id")
def add_ce_admin(self, user):
if self.hierarchy_level != 'community':
raise UserError(_("Only a CE can have CE admins"))
role_name = self._get_admin_role_name()
role = self.env["res.users.role"].sudo().search([(
"code", "=", "role_ce_admin"
"code", "=", role_name
)])
current_role = self.env["res.users.role.line"].sudo().search([
("user_id", "=", user.id),
("active", "=", True),
("company_id", "=", self.id) # It's M2M, = is okey?
("company_id", "=", self.id)
])
if current_role and len(current_role) > 1:
raise UserError(_("Error: This user have multiple roles for this company"))
......@@ -178,7 +184,7 @@ class ResCompany(models.Model):
def get_ce_members(self, domain_key="in_kc_and_active"):
domains_dict = {
"in_kc_and_active": [
("company_id", "=", self.id), # TODO: company_ids ??
("company_id", "=", self.id),
("oauth_uid", "!=", None),
("active", "=", True),
]
......
......@@ -12,7 +12,7 @@
<header>
<field name="landing_page_id" invisible="1"/>
<button name="create_landing" type="object" string="Create landing page" attrs="{'invisible': [('landing_page_id','!=',False)]}" />
<button name="action_open_assign_admin_wizard" type="object" string="Assing administrator" />
<button name="action_open_assign_admin_wizard" type="object" string="Assing administrator" groups="['group_admin','group_platform_manager','group_coordinator']"/>
</header>
</xpath>
<xpath expr="//field[@name='logo']" position="before">
......@@ -20,13 +20,6 @@
<button name="get_landing_page_form" type="object" string="My landing page" class="oe_stat_button" icon="fa-globe" attrs="{'invisible': [('landing_page_id','=',False)]}" />
</div>
<field name="admins" invisible="True"></field>
<div class='oe_button_box'>
<button name="action_open_assign_admin_wizard" type="object" string="Administrators" class="oe_stat_button" icon="fa-globe" attrs="{'invisible': [('admins','=',[])]}" />
</div>
<!-- <field name="admin_mids" invisible="True"></field>
<div class='oe_button_box'>
<button name="get_admins" type="object" string="Administrators" class="oe_stat_button" icon="fa-globe" attrs="{'invisible': [('admin_mids','=',[])]}" />
</div> -->
</xpath>
<xpath expr="//notebook" position="inside">
<page string="Energy Communities">
......
......@@ -47,7 +47,7 @@ class AssignAdminWizard(models.TransientModel):
"company_id": company_id,
"company_ids": [company_id],
"lang": self.lang.code,
"email": self.email, # It works?
"email": self.email,
}
user = self.env["res.users"].create(vals)
......
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