Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
4000 Ansichten

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

Beste Antwort

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
Verwerfen
Autor Beste Antwort

Thanks for your help. 


It's working as  expected.

Avatar
Verwerfen
Autor

Please help me ~~~

Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Juni 21
3052
1
Nov. 20
4899
2
Juni 20
3627
2
März 24
6253
1
Juli 23
2141