Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3906 Представления

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

Related Posts Ответы Просмотры Активность
0
июн. 21
3001
1
нояб. 20
4824
2
июн. 20
3588
2
мар. 24
6178
1
июл. 23
2064