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
180f93bd
Commit
180f93bd
authored
1 year ago
by
Benjami
Committed by
konykon
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
User email must be unique
parent
61c91282
No related branches found
No related tags found
3 merge requests
!239
Draft: [REL] energy_communities: dependency energy_selfconsumption bump to
,
!227
[REL] Release 16/10/23
,
!142
Feature/assign ce admin
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
energy_communities/models/res_partner.py
+10
-0
10 additions, 0 deletions
energy_communities/models/res_partner.py
energy_communities/tests/test_res_users.py
+23
-1
23 additions, 1 deletion
energy_communities/tests/test_res_users.py
with
33 additions
and
1 deletion
energy_communities/models/res_partner.py
+
10
−
0
View file @
180f93bd
import
logging
from
odoo.exceptions
import
ValidationError
from
odoo
import
SUPERUSER_ID
,
api
,
fields
,
models
...
...
@@ -28,6 +29,15 @@ class ResPartner(models.Model):
new_partner
=
super
().
create
(
vals
)
return
new_partner
@api.constrains
(
'
email
'
)
def
_check_email
(
self
):
count_users
=
self
.
env
[
'
res.partner
'
].
search_count
([
(
'
email
'
,
'
=
'
,
self
.
email
),
(
'
user_ids
'
,
'
!=
'
,
False
)
])
if
self
.
email
and
count_users
>=
1
:
raise
ValidationError
(
'
The email already registered, please use another email!
'
)
def
cron_update_company_ids_from_user
(
self
):
partner_with_users
=
self
.
search
(
[(
"
user_ids
"
,
"
!=
"
,
False
),
(
"
user_ids.id
"
,
"
!=
"
,
SUPERUSER_ID
)]
...
...
This diff is collapsed.
Click to expand it.
energy_communities/tests/test_res_users.py
+
23
−
1
View file @
180f93bd
...
...
@@ -2,7 +2,7 @@
from
faker
import
Faker
from
mock
import
patch
from
odoo.tests
import
common
from
odoo.exceptions
import
UserError
from
odoo.exceptions
import
UserError
,
ValidationError
faker
=
Faker
(
locale
=
'
es_ES
'
)
...
...
@@ -229,3 +229,25 @@ class TestResUsers(common.TransactionCase):
self
.
assertEqual
(
len
(
rl_coord
),
2
)
self
.
assertIn
(
self
.
coordination
,
self
.
coord_admin
.
company_ids
)
self
.
assertIn
(
other_coord
,
self
.
coord_admin
.
company_ids
)
@patch
(
"
odoo.addons.energy_communities.models.res_users.ResUsers.create_users_on_keycloak
"
)
@patch
(
"
odoo.addons.energy_communities.models.res_users.ResUsers.send_reset_password_mail
"
)
def
test__email_must_be_unique
(
self
,
reset_password_mocked
,
create_kc_user_mocked
):
self
.
users_model
.
create_energy_community_base_user
(
vat
=
faker
.
vat_id
(),
first_name
=
"
Tom
"
,
last_name
=
"
Bombadil
"
,
lang_code
=
"
en_US
"
,
email
=
"
random.mail@somcomunitats.coop
"
,
)
with
self
.
assertRaises
(
ValidationError
):
self
.
users_model
.
create_energy_community_base_user
(
vat
=
faker
.
vat_id
(),
first_name
=
"
Timmy
"
,
last_name
=
"
Box
"
,
lang_code
=
"
en_US
"
,
email
=
"
random.mail@somcomunitats.coop
"
,
)
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