تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4080 أدوات العرض

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
يونيو 21
3080
1
نوفمبر 20
4923
2
يونيو 20
3665
2
مارس 24
6315
1
يوليو 23
2187