跳至內容
選單
此問題已被標幟
2 回覆
6885 瀏覽次數

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
10689
3
11月 22
5881
0
8月 20
4463
1
6月 17
1282
2
9月 21
3759