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

Add admin type depends on hierarchy level

parent 217d1720
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
......@@ -155,27 +155,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"))
......@@ -201,7 +207,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),
]
......
......@@ -15,7 +15,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">
......@@ -23,13 +23,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