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

Hello everyone... once again for today,

I need your help on trying to figure out why this sql constraint does not work for the "name" field on product.template (and also with some other fields, but not all):

_sql_constraints = [
                    ('name_unique','unique(name)', _("Product name must be unique!")),
                    ]

This is a standard Odoo field and tried with some other core and custom fields and the same happens, but not with all fields.

Question arises when it works fine with other fields. For instance:

_sql_constraints = [
                    ('code_unique','unique(default_code)', _("Product code must be unique!")),
                    ]

...works great!!!

For my specific situation I had to use a Python Constrain like:

@api.multi 
@api.constrains('name') 
def _unique_name(self): 
    for record in self: 
    obj = self.search([('name','=ilike',record.name),('id','!=',record.id)]) 
    if obj: 
        raise ValidationError(_("Product name must be unique"))

Can anyone explain me why sql constraint does not work for some of the fields?
I have tested on a database with no data for the products template. I know sql constraints apply to both new and existing data and if there is some existing data that violates the constraint it does not work, but this is not the case.

Than you all in advance

PM






아바타
취소
관련 게시물 답글 화면 활동
2
3월 15
10705
3
11월 22
5894
1
6월 17
1282
2
11월 15
6918
2
9월 21
3779