Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2194 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jul 24
1605
4
Jul 21
54668
1
Jun 19
4754
2
Jan 20
3834
1
Mei 25
1359