تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
1355 أدوات العرض

Hello, I'm on odoo entreprises 17.

I want to prevent users from creating the same contact twice. By preventing users from saving the same phone number twice on two contacts

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

You can achieve it from the code or from the user interface. If you are doing from code, just add a constrain for the field and check against existing contacts and raise validation error.

See an use case with automated action:  Prevent Product Duplication without code using automated actions



Thanks

الصورة الرمزية
إهمال
أفضل إجابة

One way of doing is  by  STUDIO with below steps


Open Contact Form

Open Studio

select Phone Field - In Studio and  Mark as  UNIQUE

But  for existing records - when u open , you need to enter unique value

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thanks, I did watch the video, in fact I had also tried to do it from an automation but I think my error is in the code.

existingcontact =  env['res.partner'].search([('phone','=',record.phone)])

if len(existingcontact) > 1:

raise Warning('Ce contact est déjà enregistré !')

الصورة الرمزية
إهمال

could you share the code you added

الكاتب

existingcontact = env['res.partner'].search([('phone','=',record.phone)])
if len(existingcontact) > 1:
raise Warning('Ce contact est déjà enregistré !')

الكاتب

It's ok
I found it 1000 thanks