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

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
Zrušit
Autor

@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?

Nejlepší odpověď

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

Thanks for your help. 


It's working as  expected.

Avatar
Zrušit
Autor

Please help me ~~~

Related Posts Odpovědi Zobrazení Aktivita
0
čvn 21
2803
1
lis 20
4594
2
čvn 20
3364
2
bře 24
5853
1
čvc 23
1811