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

Hi all,

Need constraints for Customer name field doesn't allow "spaces"?. is there any sql constraints?

Please give me suggestion.


Thanks and regards!

아바타
취소
베스트 답변

Jyothimani,

I think you need a constraint to check "name should not have space".

If it's so, you can create an odoo constraint and use regular expression to check for space in name, like

first add import re(to import regular expression class) then,

def _check_name(self, cr, uid, ids, context=None): 

    for record in self.browse(cr, uid, ids, context=context): 

# checking if regular expression find any ' '(space) in name string then it will return False

        has_space = re.compile(' ').search(record.name)

        if has_space:

            return False

    return True

 and add _constraint as:

_constraints = [(_check_name, 'YOUR_MESSAGE', ['name'])]

Hop it will help!    

아바타
취소
작성자

Thanks!!!!

Thank you!!!!

베스트 답변

You can try this

def _check_string(self, cr, uid, ids, context=None):

    for data in self.browse(cr, uid, ids, context=context)

          if data.isspace() == True:

                 return False

return True

_constraints = [

(_check_string, 'Space is not allow', ['field name'])

]

아바타
취소
작성자

Very thanks Solanki Shamji!!!!!. Its working.....

관련 게시물 답글 화면 활동
2
3월 15
10683
3
11월 22
5869
0
8월 20
4445
1
6월 17
1282
2
9월 21
3745