Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2853 Näkymät

Hello i would like to override the user creation method, in order to verify if the email is used by another user or not:

class User(models.Model):
_name = 'affichage2.user'
_inherit = 'res.users'


#this is the solution
@api.model
def create(self, values):

res = super(User, self).create(vals)
exis_email_id = self.env['res.users'].search([('email', '=', vals['email'].lower())])

if exis_email_id:
raise osv.except_osv(_('Invalid Action!'), _('Email already exist.'))

return res


My solution don't working, any help please

Avatar
Hylkää
Paras vastaus
Hi Zakaria,
 
Try this code
 
class User(models.Model):
  _inherit = 'res.users'
#this is the solution
@api.model
def create(self, values):
res = super(User, self).create(vals)
exis_email_id = self.env['res.users'].search([('email', '=', vals['email'].lower())])

if exis_email_id:
raise osv.except_osv(_('Invalid Action!'), _('Email already exist.'))

return res
Thank you.
Avatar
Hylkää
Tekijä

I will try it, thank you Avinash. In which module i should put this class ? in any module ?

Better make a new one.

Tekijä

Ok. I have try your solution but the problem that i get warning message in all cases, also if the email don't exist.

Tekijä

I think because the creation is made before the verification