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
59ebb9d7
Commit
59ebb9d7
authored
1 year ago
by
Benjami
Browse files
Options
Downloads
Patches
Plain Diff
Fix last rebase errors
parent
c05a5b50
No related branches found
No related tags found
2 merge requests
!253
[REL] Release 06/11/23
,
!191
V1 imrpvements to CompanyEasyCreation wizard (CRM Lead execution)🙋
Pipeline
#45531
passed with warnings
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
energy_communities/models/res_company.py
+63
-40
63 additions, 40 deletions
energy_communities/models/res_company.py
energy_communities/tests/test_res_company.py
+34
-21
34 additions, 21 deletions
energy_communities/tests/test_res_company.py
with
97 additions
and
61 deletions
energy_communities/models/res_company.py
+
63
−
40
View file @
59ebb9d7
...
...
@@ -16,8 +16,8 @@ _HIERARCHY_LEVEL_VALUES = [
class
ResCompany
(
models
.
Model
):
_name
=
'
res.company
'
_inherit
=
[
'
res.company
'
,
"
mail.thread
"
,
"
mail.activity.mixin
"
]
_name
=
"
res.company
"
_inherit
=
[
"
res.company
"
,
"
mail.thread
"
,
"
mail.activity.mixin
"
]
@api.onchange
(
"
hierarchy_level
"
)
def
onchange_hierarchy_level
(
self
):
...
...
@@ -75,16 +75,15 @@ class ResCompany(models.Model):
comodel_name
=
"
product.template
"
,
domain
=
[(
"
is_share
"
,
"
=
"
,
True
)],
string
=
"
Voluntary share to show on website
"
,
wordpress_base_url
=
fields
.
Char
(
string
=
_
(
"
Wordpress Base URL (JWT auth)
"
)
)
wordpress_base_url
=
fields
.
Char
(
string
=
_
(
"
Wordpress Base URL (JWT auth)
"
))
admins
=
fields
.
One2many
(
'
res.users
'
,
"
res.users
"
,
string
=
"
Community admins
"
,
compute
=
'
_get_admins
'
,
compute
=
"
_get_admins
"
,
readonly
=
True
,
store
=
False
store
=
False
,
)
landing_page_id
=
fields
.
Many2one
(
"
landing.page
"
,
string
=
_
(
"
Landing Page
"
))
wordpress_db_username
=
fields
.
Char
(
string
=
_
(
"
Wordpress DB Admin Username
"
))
...
...
@@ -167,21 +166,23 @@ class ResCompany(models.Model):
return
any
([
user
in
admins_user_ids
for
user
in
company_user_ids
])
def
_get_admin_role_name
(
self
):
if
self
.
hierarchy_level
==
'
community
'
:
if
self
.
hierarchy_level
==
"
community
"
:
return
"
role_ce_admin
"
elif
self
.
hierarchy_level
==
'
coordinator
'
:
elif
self
.
hierarchy_level
==
"
coordinator
"
:
return
"
role_coord_admin
"
elif
self
.
hierarchy_level
==
'
instance
'
:
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
"
].
search
([
(
"
company_id.id
"
,
"
=
"
,
self
.
id
),
(
"
active
"
,
"
=
"
,
True
),
(
"
role_id.code
"
,
"
=
"
,
role_name
)
])
role_lines
=
self
.
env
[
"
res.users.role.line
"
].
search
(
[
(
"
company_id.id
"
,
"
=
"
,
self
.
id
),
(
"
active
"
,
"
=
"
,
True
),
(
"
role_id.code
"
,
"
=
"
,
role_name
),
]
)
rec
.
admins
=
role_lines
.
mapped
(
"
user_id
"
)
def
get_ce_members
(
self
,
domain_key
=
"
in_kc_and_active
"
):
...
...
@@ -192,30 +193,50 @@ class ResCompany(models.Model):
(
"
active
"
,
"
=
"
,
True
),
]
}
return
self
.
env
[
"
res.users
"
].
sudo
().
search
(
domains_dict
[
"
in_kc_and_active
"
]
)
return
self
.
env
[
"
res.users
"
].
sudo
().
search
(
domains_dict
[
"
in_kc_and_active
"
])
def
get_users
(
self
,
role_codes
=
[]
):
def
get_users
(
self
,
role_codes
=
False
):
if
role_codes
:
users
=
self
.
env
[
"
res.users.role.line
"
].
search
([
(
"
company_id
"
,
"
=
"
,
self
.
id
),
(
"
role_id.code
"
,
"
in
"
,
role_codes
),
]).
user_id
users
=
(
self
.
env
[
"
res.users.role.line
"
]
.
search
(
[
(
"
company_id
"
,
"
=
"
,
self
.
id
),
(
"
role_id.code
"
,
"
in
"
,
role_codes
),
]
)
.
user_id
)
else
:
users
=
self
.
env
[
"
res.users.role.line
"
].
search
([
(
"
company_id
"
,
"
=
"
,
self
.
id
),
]).
user_id
users
=
(
self
.
env
[
"
res.users.role.line
"
]
.
search
(
[
(
"
company_id
"
,
"
=
"
,
self
.
id
),
]
)
.
user_id
)
wants_platform_admins
=
(
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
code
in
role_codes
or
not
role_codes
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
code
in
role_codes
or
not
role_codes
)
if
wants_platform_admins
:
users
+=
self
.
env
[
"
res.users.role.line
"
].
search
([
(
"
role_id
"
,
"
=
"
,
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
id
),
]).
user_id
users
+=
(
self
.
env
[
"
res.users.role.line
"
]
.
search
(
[
(
"
role_id
"
,
"
=
"
,
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
id
,
),
]
)
.
user_id
)
return
users
# return lines.user_id # TODO: Si?
...
...
@@ -266,17 +287,19 @@ class ResCompany(models.Model):
return
res
def
get_lower_hierarchy_level
(
self
):
if
self
.
hierarchy_level
==
'
instance
'
:
return
'
coordinator
'
elif
self
.
hierarchy_level
==
'
coordinator
'
:
return
'
community
'
return
''
if
self
.
hierarchy_level
==
"
instance
"
:
return
"
coordinator
"
elif
self
.
hierarchy_level
==
"
coordinator
"
:
return
"
community
"
return
""
def
get_child_companies
(
self
):
return
self
.
env
[
'
res.company
'
].
search
([
(
'
hierarchy_level
'
,
'
=
'
,
self
.
get_lower_hierarchy_level
()),
(
'
parent_id
'
,
'
=
'
,
self
.
id
),
])
return
self
.
env
[
"
res.company
"
].
search
(
[
(
"
hierarchy_level
"
,
"
=
"
,
self
.
get_lower_hierarchy_level
()),
(
"
parent_id
"
,
"
=
"
,
self
.
id
),
]
)
def
get_public_web_landing_url
(
self
):
# TODO: Get from landing page or company, for now we don't need
...
...
This diff is collapsed.
Click to expand it.
energy_communities/tests/test_res_company.py
+
34
−
21
View file @
59ebb9d7
from
odoo.exceptions
import
ValidationError
<<<<<<<
HEAD
from
odoo.tests
import
common
class
TestResCompany
(
common
.
SingleTransactionCase
):
=======
from
.helpers
import
CompanySetupMixin
,
UserSetupMixin
class
TestResCompany
(
CompanySetupMixin
,
UserSetupMixin
,
common
.
TransactionCase
):
>>>>>>>
refactor
to
test
helper
methods
🎆
def
test_hierarchy_level_company_instance
(
self
):
company_instance
=
self
.
env
[
"
res.company
"
].
search
(
[(
"
hierarchy_level
"
,
"
=
"
,
"
instance
"
)]
...
...
@@ -96,15 +90,22 @@ class TestResCompany(CompanySetupMixin, UserSetupMixin, common.TransactionCase):
}
)
with
self
.
assertRaises
(
ValidationError
):
self
.
env
[
'
res.company
'
].
create
(
{
'
name
'
:
'
Community Company Error 2
'
,
'
hierarchy_level
'
:
'
community
'
,
'
parent_id
'
:
company_community
.
id
})
self
.
env
[
"
res.company
"
].
create
(
{
"
name
"
:
"
Community Company Error 2
"
,
"
hierarchy_level
"
:
"
community
"
,
"
parent_id
"
:
company_community
.
id
,
}
)
def
test__get_users__without_roles
(
self
):
# Given a coord company and coord admin
company_instance
=
self
.
env
[
'
res.company
'
].
search
([(
'
hierarchy_level
'
,
'
=
'
,
'
instance
'
)])
company_coordinator
=
self
.
create_company
(
"
Som
"
,
"
coordinator
"
,
company_instance
.
id
)
company_instance
=
self
.
env
[
"
res.company
"
].
search
(
[(
"
hierarchy_level
"
,
"
=
"
,
"
instance
"
)]
)
company_coordinator
=
self
.
create_company
(
"
Som
"
,
"
coordinator
"
,
company_instance
.
id
)
user
=
self
.
create_user
(
"
Tom
"
,
"
Bombadil
"
)
self
.
make_coord_user
(
company_coordinator
,
user
)
...
...
@@ -112,17 +113,29 @@ class TestResCompany(CompanySetupMixin, UserSetupMixin, common.TransactionCase):
community_users
=
company_coordinator
.
get_users
()
# Then returns all community users
platform_admins
=
self
.
env
[
"
res.users.role.line
"
].
search
([
(
"
role_id
"
,
"
=
"
,
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
id
),
]).
user_id
self
.
assertEquals
(
community_users
,
user
+
platform_admins
)
platform_admins
=
(
self
.
env
[
"
res.users.role.line
"
]
.
search
(
[
(
"
role_id
"
,
"
=
"
,
self
.
env
.
ref
(
"
energy_communities.role_platform_admin
"
).
id
,
),
]
)
.
user_id
)
self
.
assertEqual
(
community_users
,
user
+
platform_admins
)
def
test__get_users__with_roles
(
self
):
# Given a coord company and coord admin
company_instance
=
self
.
env
[
'
res.company
'
].
search
([(
'
hierarchy_level
'
,
'
=
'
,
'
instance
'
)])
company_coordinator
=
self
.
create_company
(
"
Som
"
,
"
coordinator
"
,
company_instance
.
id
)
company_instance
=
self
.
env
[
"
res.company
"
].
search
(
[(
"
hierarchy_level
"
,
"
=
"
,
"
instance
"
)]
)
company_coordinator
=
self
.
create_company
(
"
Som
"
,
"
coordinator
"
,
company_instance
.
id
)
first_user
=
self
.
create_user
(
"
Tom
"
,
"
Bombadil
"
)
second_user
=
self
.
create_user
(
"
Frodo
"
,
"
Baggins
"
)
self
.
make_coord_user
(
company_coordinator
,
first_user
)
...
...
@@ -132,4 +145,4 @@ class TestResCompany(CompanySetupMixin, UserSetupMixin, common.TransactionCase):
community_users
=
company_coordinator
.
get_users
([
"
role_coord_worker
"
])
# Then returns all community users
self
.
assertEqual
s
(
community_users
,
second_user
)
self
.
assertEqual
(
community_users
,
second_user
)
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