Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2208 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvc 24
1644
4
čvc 21
54709
1
čvn 19
4770
2
led 20
3851
1
kvě 25
1406