Skip to Content
Menú
This question has been flagged
1 Respondre
2191 Vistes

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
Best Answer

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
Related Posts Respostes Vistes Activitat
1
de jul. 24
1595
4
de jul. 21
54646
1
de juny 19
4742
2
de gen. 20
3827
1
de maig 25
1340