Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odoo CE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Comunitats Energètiques
Odoo CE
Commits
0121876e
Commit
0121876e
authored
1 year ago
by
Benjami
Browse files
Options
Downloads
Patches
Plain Diff
Add admin into communiy energy
parent
96b81b70
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
energy_communities/models/res_company.py
+33
-0
33 additions, 0 deletions
energy_communities/models/res_company.py
with
33 additions
and
0 deletions
energy_communities/models/res_company.py
+
33
−
0
View file @
0121876e
...
...
@@ -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
"
:
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment