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

Remove unique email constraint and improve assign admin search

parent 7f596034
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
This commit is part of merge request !142. Comments created here will be created in the context of that merge request.
......@@ -29,14 +29,14 @@ 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 > 0:
raise ValidationError('The email already registered, please use another email!')
# @api.constrains('email') # TODO: Remove!!
# def _check_email(self):
# count_users = self.env['res.partner'].search_count([
# ('email', '=', self.email),
# ('user_ids', '!=', False)
# ])
# if self.email and count_users > 0:
# raise ValidationError(_('The email already registered, please use another email!'))
def cron_update_company_ids_from_user(self):
partner_with_users = self.search(
......
......@@ -165,25 +165,3 @@ class TestResUsers(CompanySetupMixin, UserSetupMixin, 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",
)
......@@ -31,7 +31,6 @@ class AssignAdminWizard(models.TransientModel):
return []
def process_data(self):
company_id = self.env.company.id
if self.is_new_admin:
user = self.env['res.users'].create_energy_community_base_user(
vat=self.vat,
......@@ -41,8 +40,13 @@ class AssignAdminWizard(models.TransientModel):
email=self.email,
)
else:
user = self.env['res.users'].search([('login', '=', self.vat)])
user = self.env['res.users'].search([
('login', 'ilike', self.vat)
], limit=1)
if not user:
raise ValidationError(_('User not found'))
company_id = self.env.company.id
user.add_energy_community_role(company_id, self.role)
return True
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