Skip to content
Snippets Groups Projects
Commit 13c9afba authored by Benjami's avatar Benjami
Browse files

Remove unique email constraint and improve assign admin search

parent 5d8e17e2
No related branches found
No related tags found
2 merge requests!253[REL] Release 06/11/23,!191V1 imrpvements to CompanyEasyCreation wizard (CRM Lead execution)🙋‍
......@@ -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