跳至內容
選單
此問題已被標幟
2 回覆
3943 瀏覽次數

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 ...

頭像
捨棄
作者

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

最佳答案

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!")

頭像
捨棄
作者 最佳答案

Thanks for your help. 


It's working as  expected.

頭像
捨棄
作者

Please help me ~~~

相關帖文 回覆 瀏覽次數 活動
0
6月 21
3039
1
11月 20
4856
2
6月 20
3605
2
3月 24
6206
1
7月 23
2092