Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
3976 Vues

Create @api.constrains to check: 

_sql_constraints = [
        (
            "phone_owner_uniq",
            "unique (phone, owner)",
            "You cannot have two tenants with the same phone number for the same owner!",
        )
    ]

This is sql.contrains but I want to check with python constrains.

Please help me ...

Avatar
Ignorer
Auteur

@Kiran K
In odoo, it's working.
But in my app (FE: React native), It show error message, but it still create.
Is there any way to fix it?

Meilleure réponse

Hi BB,

Try,

    @api.constrains('phone', 'owner')

    def check_phone_owner_uniq(self):

        for record in self:

            duplicate_records = self.search([

                ('phone', '=', record.phone),

                ('owner', '=', record.owner.id),

                ('id', '!=', record.id)

            ])

            if duplicate_records:

                raise ValidationError("You cannot have two tenants with the same phone number for the same owner!")

Avatar
Ignorer
Auteur Meilleure réponse

Thanks for your help. 


It's working as  expected.

Avatar
Ignorer
Auteur

Please help me ~~~

Publications associées Réponses Vues Activité
0
juin 21
3049
1
nov. 20
4888
2
juin 20
3616
2
mars 24
6234
1
juil. 23
2129