Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2197 Vistas

In the case that the customer already exists and the Salesperson is the same user, but he does not complete the creation process and shows a message that the customer already exists.

whats the code i do it 

note i inhert selection field (red,orange,green)

this is case in red

@api.constrains('website')
def _check_validation(self):
if self.website:
res = self.search([('website', '=', self.website), ], limit=1)
if res:
raise ValidationError(_("Website Must Be Unique."))



Avatar
Descartar
Mejor respuesta

Hi,

If you want to make the contact unique, you can do that easily with Automated Actions or Add constraints to the model.

Automated Action

Enable Developer Mode, Then Go to Settings-> Technical -> Automated Actions

Click Create and enter the following:

Model             : Contact
Action To Do  : Execute python code
Active             : True
Trigger           : On Creation & Update

Python Code

if record.name:
partner = env['res.partner'].search([('id','!=',record.id),('name','=',record.name),('user_id','=',record.user_id.id)])
if partner:
raise UserError("Name should be unique")

Constraints

class ResPartner(models.Model):
_inherit = 'res.partner'
    @api.constrains('name')
    def _check_name(self):
        partner = env['res.partner'].search([('id','!=',self.id),('name','=',self.name),('user_id','=',self.user_id.id)])
    if partner:
    raise UserError("Name should be unique")


Regards

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 24
1609
4
jul 21
54677
1
jun 19
4756
2
ene 20
3836
1
may 25
1362