Skip to Content
Menu
This question has been flagged

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
Discard
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
Discard
Related Posts Replies Views Activity
1
Jul 24
328
4
Jul 21
52087
1
Jun 19
3665
2
Jan 20
3114
2
Dec 24
133