İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
3626 Görünümler

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
Vazgeç
Üretici

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

En İyi Yanıt

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
Vazgeç
Üretici En İyi Yanıt

Thanks for your help. 


It's working as  expected.

Avatar
Vazgeç
Üretici

Please help me ~~~

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Haz 21
2826
1
Kas 20
4625
2
Haz 20
3388
2
Mar 24
5912
1
Tem 23
1880