Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4149 Tampilan

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
Buang
Penulis

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

Jawaban Terbai

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

Thanks for your help. 


It's working as  expected.

Avatar
Buang
Penulis

Please help me ~~~

Post Terkait Replies Tampilan Aktivitas
0
Jun 21
3090
1
Nov 20
4932
2
Jun 20
3690
2
Mar 24
6355
1
Jul 23
2207