콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4008 화면

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
3058
1
11월 20
4900
2
6월 20
3638
2
3월 24
6264
1
7월 23
2147