跳至内容
菜单
此问题已终结
2 回复
4982 查看

how can I check duplicate email when create new customers? Can anybody help me ? Thanks!

形象
丢弃
编写者 最佳答案

Can I use sqlconstraints to check duplicate email like this? 

_sql_constraints = [ ('email_unique',   'UNIQUE(email)',   "The Email must be unique"), ]

Are you Vietnamese, Can you contact with me?
My email address: volamtruong01999@gmail.com

形象
丢弃

Yes, why don't you try it now XD

编写者

I was tried but it doesn't working for me

Try this

@api.constrains('email')

def _check_duplicate_email(self):

for rec in self:

emails = self.env['res.partner'].search([('email', '=', rec.email)])

for obj in emails:

if obj.email:

raise ValidationError("Duplicate Email")

最佳答案

Hi, there are many ways

- Use Data Cleaning Apps (Odoo14 EE): It will find all duplicate records for you

- Use search bar (if you know which email is duplicated)

- Create a custom groupby for email field and find all the emails which have more than 1 record

- Create automated action (Odoo EE): and write python code to check the email field

- overwrite the create function of model res.partner

形象
丢弃
相关帖文 回复 查看 活动
1
2月 25
1242
0
4月 21
2216
4
5月 24
38475
1
3月 24
2651
2
12月 20
6175